QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#886415#9519. Build a Computerlin23333AC ✓1ms3968kbC++143.0kb2025-02-07 02:02:482025-02-07 02:02:49

Judging History

This is the latest submission verdict.

  • [2025-02-07 02:02:49]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3968kb
  • [2025-02-07 02:02:48]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

int aim;
int st1,st2;
int ls,ld,st,ed;
int bs[22],bd[22];

int hd,top;
int cnt[110];

struct node{
	int to,val;
	node(int TO,int VAL):to(TO),val(VAL) {}
	bool operator < (const node &another) const{
		return to<another.to;
	}
};

multiset<node> s[110];
multiset<node>::iterator t;

void planA(){
	for(int i=hd;i>ls;i--){
		s[hd].insert(node(i-1,1));
		cnt[hd]+=1;
	}return;
}

void partB(int now){
	
	if(now>ls){
		return;
	}
	
	if(now==ls){
		if(bs[ls]==0){
			s[top].insert(node(0,0));
			cnt[top]+=1;
		}s[top].insert(node(0,1));
		cnt[top]+=1;
		return;
	}
	
	if(bs[now]==0){
		s[top].insert(node(ls-now,1));
		s[top].insert(node(top+1,0));
		cnt[top]+=2;
	}else{
		s[top].insert(node(top+1,1));
		cnt[top]+=1;
	}
	
	top+=1;
	partB(now+1);
	
	return;
}

void partC(int now){
	
	if(now>ld){
		return;
	}
	
	if(now==ld){
		if(bd[ld]==1){
			s[top].insert(node(0,1));
			cnt[top]+=1;
		}s[top].insert(node(0,0));
		cnt[top]+=1;
		return;
	}
	
	if(bd[now]==1){
		s[top].insert(node(ld-now,0));
		s[top].insert(node(top+1,1));
		cnt[top]+=2;
	}else{
		s[top].insert(node(top+1,0));
		cnt[top]+=1;
	}
	
	top+=1;
	partC(now+1);
	
	return;
}

int main(){
	
	scanf("%d%d",&st,&ed);
	
	if(st==ed){
		for(;st!=0;){
			ls+=1;
			bs[ls]=st%2;
			st/=2;
		}st=ed;
		
		printf("%d\n",ls+1);
		printf("0\n");
		for(int i=1;i<=ls;i++){
			printf("1 %d %d\n",i,st%2);
			st/=2;
		}return 0;
		
	}
	
	for(;st!=0;){
		ls+=1;
		bs[ls]=st%2;
		st/=2;
	}for(;ed!=0;){
		ld+=1;
		bd[ld]=ed%2;
		ed/=2;
	}for(int i=1;i<=ls/2;i++){
		swap(bs[i],bs[ls-i+1]);
	}for(int i=1;i<=ld/2;i++){
		swap(bd[i],bd[ld-i+1]);
	}
	
	if(ls==ld){
		int jd=0;
		for(int i=1;i<=ls;i++){
			if(jd==1){
				if(bs[i]==0){
					aim=max(ls-i,aim);
				}if(bd[i]==1){
					aim=max(ld-i,aim);
				}
			}if(bs[i]!=bd[i]&&jd==0){
				jd=1;
				st1=i;
				st2=i;
			}
		}
	}else{
		st1=1;
		st2=1;
	}
	
	if(ls+1==ld){
		for(int i=1;i<=ls;i++){
			if(bs[i]==0){
				aim=max(aim,ls-i);
			}
		}for(int i=2;i<=ld;i++){
			if(bd[i]==1){
				aim=max(aim,ld-i);
			}
		}
	}if(ls+1<ld){
		aim=ld-2;
	}
	
	for(int i=aim;i>0;i--){
		s[i].insert(node(i-1,1));
		s[i].insert(node(i-1,0));
		cnt[i]+=2;
	}
	
	top=aim+1;
	if(ls==ld){
		for(int i=1;i>0;i++){
			if(bs[i]!=bd[i]){
				break;
			}s[top].insert(node(top+1,bs[i]));
			cnt[top]+=1;
			top+=1;
		}
	}
	
	hd=top;
	planA();
	
	if(st1!=ls){
		top+=1;
		s[hd].insert(node(top,bs[st1]));
		cnt[hd]+=1;
		partB(st1+1);
	}else{
		s[hd].insert(node(0,bs[st1]));
		cnt[hd]+=1;
	}
	
	if(st2!=ld){
		top+=1;
		s[hd].insert(node(top,bd[st2]));
		cnt[hd]+=1;
		partC(st2+1);
	}else{
		s[hd].insert(node(0,bd[st2]));
		cnt[hd]+=1;
	}
	
	printf("%d\n",top+1);
	for(int i=0;i<=top;i++){
		printf("%d",cnt[i]);
		t=s[i].begin();
		for(;t!=s[i].end();t++){
			printf(" %d %d",(*t).to+1,(*t).val);
		}printf("\n");
	}
	
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

5 7

output:

5
0
1 3 1
2 4 0 5 1
1 1 1
2 1 1 1 0

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

10 27

output:

12
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 6 1 9 1
2 3 1 7 0
1 8 1
2 1 0 1 1
2 4 0 10 1
1 11 0
2 2 0 12 1
2 1 1 1 0

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

5 13

output:

9
0
2 1 1 1 0
2 2 1 2 0
2 5 1 7 1
2 2 1 6 0
1 1 1
2 3 0 8 1
1 9 0
2 1 1 1 0

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 1000000

output:

39
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
20 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 21 1
2 1...

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 1

output:

2
0
1 1 1

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

7 9

output:

7
0
2 3 1 5 1
1 4 1
1 1 1
1 6 0
1 7 0
2 1 1 1 0

result:

ok ok

Test #7:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

3 7

output:

6
0
2 1 1 1 0
2 4 1 5 1
1 1 1
2 2 0 6 1
2 1 1 1 0

result:

ok ok

Test #8:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

1 5

output:

5
0
2 1 1 1 0
3 1 1 2 1 4 1
1 5 0
2 1 1 1 0

result:

ok ok

Test #9:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

1 4

output:

5
0
2 1 1 1 0
3 1 1 2 1 4 1
1 5 0
1 1 0

result:

ok ok

Test #10:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

8 9

output:

5
0
1 3 1
1 4 0
1 5 0
2 1 0 1 1

result:

ok ok

Test #11:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

7 51

output:

13
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
4 4 1 5 1 7 1 9 1
1 8 1
1 1 1
2 5 0 10 1
1 11 0
1 12 0
2 2 0 13 1
2 1 1 1 0

result:

ok ok

Test #12:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

51 79

output:

16
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 6 1 11 1
1 7 1
2 4 1 8 0
2 3 1 9 0
1 10 1
1 1 1
1 12 0
1 13 0
2 4 0 14 1
2 3 0 15 1
2 2 0 16 1
2 1 1 1 0

result:

ok ok

Test #13:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

92 99

output:

14
0
2 1 1 1 0
1 4 1
2 5 0 10 1
1 6 1
1 7 1
1 8 1
2 2 1 9 0
2 1 0 1 1
1 11 0
1 12 0
1 13 0
2 2 0 14 1
2 1 1 1 0

result:

ok ok

Test #14:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

27 36

output:

13
0
2 1 1 1 0
2 2 1 2 0
2 5 1 9 1
1 6 1
2 3 1 7 0
1 8 1
1 1 1
1 10 0
1 11 0
2 3 0 12 1
1 13 0
1 1 0

result:

ok ok

Test #15:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

55 84

output:

17
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 7 1 12 1
1 8 1
2 4 1 9 0
1 10 1
1 11 1
1 1 1
1 13 0
2 5 0 14 1
1 15 0
2 3 0 16 1
1 17 0
1 1 0

result:

ok ok

Test #16:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

297208 929600

output:

57
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
2 21 1 39 1
2 18 1 22 0
2 17 1 23 0
1 24 1
2 15 1 25 0
2 14 1 26 0
2 13 1 27 0
1 28 1
2 11 1 29 0...

result:

ok ok

Test #17:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

45728 589156

output:

54
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
5 17 1 18 1 19 1 21 1 36 1
2 15 1 22 0
1 23 1
1 24 1
2 12 1 25 0
2 11 1 26 0
1 27 1
2 9 1 28 0
1 ...

result:

ok ok

Test #18:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

129152 138000

output:

47
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 15 1 31 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
2 11 1 21 0
2 10 1 22 0
2 9 1 23 0
1 24 1
2 7 1 25 0
2 6 1 26 0
2 5 1 27 0
2 4 1 28 0
2 3 1 29 0
2 2 1 30 0
2 1 0 1 1
1 32...

result:

ok ok

Test #19:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

245280 654141

output:

56
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
3 19 1 21 1 38 1
1 22 1
1 23 1
2 15 1 24 0
1 25 1
1 26 1
1 27 1
1 28 1
1 29 1
2 9 1 30 0
2 8 1 31...

result:

ok ok

Test #20:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

202985 296000

output:

52
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 18 1 35 1
1 19 1
2 16 1 20 0
2 15 1 21 0
2 14 1 22 0
1 23 1
1 24 1
2 11 1 25 0
2 10 1 26 0
2 9 1 27 0
1 28 1
1 29 1
1 30 1
2 5 1 31...

result:

ok ok

Test #21:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

438671 951305

output:

57
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
2 21 1 39 1
1 22 1
2 17 1 23 0
1 24 1
2 15 1 25 0
1 26 1
1 27 1
2 12 1 28 0
2 11 1 29 0
2 10 1 30...

result:

ok ok

Test #22:

score: 0
Accepted
time: 0ms
memory: 3968kb

input:

425249 739633

output:

56
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 20 1 38 1
1 21 1
2 17 1 22 0
2 16 1 23 0
1 24 1
1 25 1
1 26 1
1 27 1
1 28 1
2 10 1 29 0
1 30 1
2 8 1 31 0
2...

result:

ok ok

Test #23:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

551207 961718

output:

56
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
1 20 1
2 21 0 39 1
2 18 1 22 0
2 17 1 23 0
2 16 1 24 0
1 25 1
1 26 1
2 13 1 27 0
1 28 1
2 11 1 29 0
2 10 1 30...

result:

ok ok

Test #24:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

114691 598186

output:

55
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
2 16 1 16 0
2 17 1 17 0
2 18 1 18 0
4 18 1 19 1 21 1 37 1
1 22 1
1 23 1
2 14 1 24 0
2 13 1 25 0
2 12 1 26 0
2 11 1 27 0
2 10 1 28 0
2...

result:

ok ok

Test #25:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

234654 253129

output:

46
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
1 16 1
1 17 1
1 18 1
2 19 0 33 1
2 14 1 20 0
1 21 1
2 12 1 22 0
1 23 1
2 10 1 24 0
2 9 1 25 0
1 26 1
2 7 1 27 0
2 6 1 28 0
1 29 1
1 30 1
1 31 1
1 32 1
2 1 0 ...

result:

ok ok

Test #26:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

554090 608599

output:

52
0
2 1 1 1 0
2 2 1 2 0
2 3 1 3 0
2 4 1 4 0
2 5 1 5 0
2 6 1 6 0
2 7 1 7 0
2 8 1 8 0
2 9 1 9 0
2 10 1 10 0
2 11 1 11 0
2 12 1 12 0
2 13 1 13 0
2 14 1 14 0
2 15 1 15 0
1 18 1
1 19 0
1 20 0
2 21 0 37 1
2 16 1 22 0
1 23 1
1 24 1
1 25 1
2 12 1 26 0
1 27 1
2 10 1 28 0
2 9 1 29 0
2 8 1 30 0
1 31 1
1 32 1
...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed