QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687567#9519. Build a Computerlzx2017AC ✓1ms3732kbC++204.2kb2024-10-29 19:45:022024-10-29 19:45:03

Judging History

This is the latest submission verdict.

  • [2024-10-29 19:45:03]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3732kb
  • [2024-10-29 19:45:02]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int i,j,n,m,k,l,x,y,a[31],b[31],L,R,f[3001],num,ss,tt,mx,wz[3001];
vector<pair<int,int> > G[301];
signed main()
{
//	freopen("1.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>L>>R;
    x=L;while(x){a[++a[0]]=x%2;x/=2;}
    x=R;while(x){b[++b[0]]=x%2;x/=2;}
    ss=1;tt=2;num=2;
    if(a[0]!=b[0])
    {
        if(b[0]-1>=a[0]+1) mx=b[0]-2;
        for(int i=b[0]-1;i>=1;i--) if(b[i]==1) mx=max(mx,i-1);
        for(int i=a[0]-1;i>=1;i--) if(a[i]==0) mx=max(mx,i-1);
        int pre=tt;
        for(int i=1;i<=mx;i++){
            wz[i]=++num;
            G[wz[i]].push_back({pre,1});
            G[wz[i]].push_back({pre,0});
            pre=wz[i];
        }
        for(int i=b[0]-1;i>=a[0]+1;i--){
            if(i-1>0){
                G[ss].push_back({wz[i-1],1});
            } else {
                G[ss].push_back({tt,1});
            }
        }
        int now=++num;
        G[ss].push_back({now,1});
        for(int i=b[0]-1;i>=1;i--){
           if(i==1) {
                if(b[i]==0) G[now].push_back({tt,0});
                else G[now].push_back({tt,0}),G[now].push_back({tt,1});
            } else {
                if(b[i]==0) {G[now].push_back({++num,0});now=num;}
                else {
                    G[now].push_back({wz[i-1],0});
                    G[now].push_back({++num,1});
                    now=num;
                }
            }
        }
        if(a[0]!=1){
        now=++num;
        G[ss].push_back({now,1});
        for(int i=a[0]-1;i>=1;i--){
            if(i==1) {
                if(a[i]==1) G[now].push_back({tt,1});
                else G[now].push_back({tt,0}),G[now].push_back({tt,1});
            } else {
                if(a[i]==1) {G[now].push_back({++num,1});now=num;}
                else {
                    G[now].push_back({wz[i-1],1});
                    G[now].push_back({++num,0});
                    now=num;
                }
            }
        }
    	} else {
    		G[ss].push_back({tt,1});
		}
    } else {
        int now=ss;int aim=0;
        for(int i=a[0];i>=1;i--) if(a[i]==b[i]) {
        	if(i!=1){
        		G[now].push_back({++num,a[i]});
          	  	now=num;	
			} else G[now].push_back({tt,a[i]});
        } else {
            aim=i;
            break;
        }  
        
        if(aim==1){
            G[now].push_back({tt,1});
            G[now].push_back({tt,0});
        } else if(aim>1){
            x=++num;y=++num;
            G[now].push_back({x,1});
            G[now].push_back({y,0});
            for(int i=aim-1;i>=2;i--) if(b[i]==1) mx=max(mx,i-1);
            for(int i=aim-1;i>=2;i--) if(a[i]==0) mx=max(mx,i-1);
            int pre=tt;
       		for(int i=1;i<=mx;i++){
            	wz[i]=++num;
            	G[wz[i]].push_back({pre,1});
            	G[wz[i]].push_back({pre,0});
            	pre=wz[i];
        	}
            for(int i=aim-1;i>=1;i--){
                if(i==1) {
                    if(b[i]==0) G[x].push_back({tt,0});
                    else G[x].push_back({tt,0}),G[x].push_back({tt,1});
                } else {
                    if(b[i]==0) {G[x].push_back({++num,0});x=num;}
                    else {
                        G[x].push_back({wz[i-1],0});
                        G[x].push_back({++num,1});
                        x=num;
                    }
                }
            }
            for(int i=aim-1;i>=1;i--){
                if(i==1) {
                    if(a[i]==1) G[y].push_back({tt,1});
                    else G[y].push_back({tt,0}),G[y].push_back({tt,1});
                } else {
                    if(a[i]==1) {G[y].push_back({++num,1});y=num;}
                    else {
                        G[y].push_back({wz[i-1],1});
                        G[y].push_back({++num,0});
                        y=num;
                    }
                }
            }
        }
    }
    cout<<num<<endl;
    for(int i=1;i<=num;i++){
        cout<<G[i].size()<<" ";
        for(int j=0;j<G[i].size();j++) cout<<G[i][j].first<<" "<<G[i][j].second<<" ";
        cout<<"\n";
    }
}

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

詳細信息

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

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

input:

1 1000000

output:

39
20 20 1 19 1 18 1 17 1 16 1 15 1 14 1 13 1 12 1 11 1 10 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 21 1 2 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...

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

input:

8 9

output:

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

result:

ok ok

Test #11:

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

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

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

input:

297208 929600

output:

57
2 21 1 40 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 19 1 19 0 
2 20 0 22 1 
2 19 0 23 1 
1 24 0 
1 25 0 
1 26 0 
2 15 0 27 1 
...

result:

ok ok

Test #17:

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

input:

45728 589156

output:

54
5 20 1 19 1 18 1 21 1 40 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 19 1 19 0 
1 22 0 
1 23 0 
1 24 0 
2 17 0 25 1 
2 16 0 26 1...

result:

ok ok

Test #18:

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

input:

129152 138000

output:

47
2 15 1 32 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 0 
1 17 0 
1 18 0 
1 19 0 
2 14 0 20 1 
2 13 0 21 1 
1 22 0 
2 11 0 23 1 
2 10 0 24 1 
1 25 0 
1 26 0 
1 27 0 
2 6 0 28 1 
1 29 0 
1 30 ...

result:

ok ok

Test #19:

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

input:

245280 654141

output:

56
3 20 1 21 1 40 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 19 1 19 0 
1 22 0 
1 23 0 
2 18 0 24 1 
2 17 0 25 1 
2 16 0 26 1 
2 1...

result:

ok ok

Test #20:

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

input:

202985 296000

output:

52
2 18 1 36 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 
1 19 0 
1 20 0 
2 17 0 21 1 
1 22 0 
1 23 0 
1 24 0 
1 25 0 
2 12 0 26 1 
1 27 0 
1 28 0 
1 29 0 
2 8 ...

result:

ok ok

Test #21:

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

input:

438671 951305

output:

57
2 21 1 40 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 19 1 19 0 
2 20 0 22 1 
2 19 0 23 1 
1 24 0 
2 17 0 25 1 
1 26 0 
1 27 0 
...

result:

ok ok

Test #22:

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

input:

425249 739633

output:

56
2 20 1 39 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 
1 21 0 
2 19 0 22 1 
2 18 0 23 1 
1 24 0 
2 16 0 25 1 
1 26 0 
1 27 0 
2 13 ...

result:

ok ok

Test #23:

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

input:

551207 961718

output:

56
1 3 1 
0 
2 4 1 5 0 
2 22 0 23 1 
2 22 1 40 0 
2 2 1 2 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 19 1 19 0 
2 20 1 20 0 
2 21 1 21 0 
1 24 0 
2 20 0 25 1 
1 26 0 
2 18 0 27 ...

result:

ok ok

Test #24:

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

input:

114691 598186

output:

55
4 20 1 19 1 21 1 40 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 19 1 19 0 
1 22 0 
1 23 0 
2 18 0 24 1 
1 25 0 
1 26 0 
2 15 0 2...

result:

ok ok

Test #25:

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

input:

234654 253129

output:

46
1 3 1 
0 
1 4 1 
1 5 1 
2 6 1 7 0 
1 21 0 
2 20 1 34 0 
2 2 1 2 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 19 1 19 0 
2 19 0 22 1 
2 18 0 23 1 
2 17 0 24 1 
1 25 0 
1 26 0 
2 14 0 27 1 
2 13 0 28 ...

result:

ok ok

Test #26:

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

input:

554090 608599

output:

52
1 3 1 
0 
1 4 0 
1 5 0 
2 6 1 7 0 
1 23 0 
2 22 1 38 0 
2 2 1 2 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 19 1 19 0 
2 20 1 20 0 
2 21 1 21 0 
2 21 0 24 1 
1 25 0 
1 26 0 
2 18 0 27 1 
1 28 0 
1 ...

result:

ok ok

Extra Test:

score: 0
Extra Test Passed