QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#712849#9519. Build a Computer2018haha#AC ✓46ms7756kbC++202.8kb2024-11-05 17:17:462024-11-05 17:17:46

Judging History

This is the latest submission verdict.

  • [2024-11-05 17:17:46]
  • Judged
  • Verdict: AC
  • Time: 46ms
  • Memory: 7756kb
  • [2024-11-05 17:17:46]
  • Submitted

answer

#include<bits/stdc++.h>

using namespace std;

const int N=100;

int cnt;
int M=20;
vector<pair<int,int>> G[N];
int len(int x)
{
    for(int j=M;j>=0;j--)
        if((x>>j)&1) return j;
    return -1;
}
int tong[1000010];
void Dfs(int u,string s)
{
    if(G[u].size()==0)
    {
        // cout<<s<<"\n";
        int tmp=0;
        for(auto x:s)
            tmp*=2,tmp+=x-'0';
        tong[tmp]++;
        return;
    }
    for(auto [v,w]:G[u])
    {
        Dfs(v,s+char(w+'0'));
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int L,R;
    cin>>L>>R;
    int S=++cnt;
    int T=++cnt;
    vector<int> id(30);
    auto Id = [&](int x){
        if(!id[x])
        {
            for(int i=1;i<=x;i++)
            {
                if(!id[i]) id[i]=++cnt;
                G[id[i]].emplace_back(id[i-1],0);
                G[id[i]].emplace_back(id[i-1],1);
            }
        }
        return id[x];
    };
    id[0]=T;
    int lenL=len(L),lenR=len(R);
    auto Gen = [&](int num,int s,int len,int mark)->void
    {
        int u=s;
        for(int j=len;j>=0;j--)
        {
            int v;
            if(j) v=++cnt;
            else v=T;
            int c=(num>>j)&1;
            G[u].emplace_back(v,c);
            if(c==mark && j!=len) G[u].emplace_back(Id(j),mark^1);
            u=v;
        }
    };
    if(lenL!=lenR)
    {
        //>=L
        Gen(L,S,lenL,0);
        //<=R
        Gen(R,S,lenR,1);
        // //lenL+1,lenR-1
        for(int i=lenL+1;i<=lenR-1;i++)
            G[S].emplace_back(Id(i),1);
    }
    else
    {
        int u=S;
        for(int j=lenL;j>=0;j--)
        {
            int lc=(L>>j)&1;
            int rc=(R>>j)&1;
            if(lc==rc)
            {
                int v;
                if(j==0) v=T;
                else v=++cnt;
                G[u].emplace_back(v,lc);
                u=v;
            }
            else
            {
                // cerr<<"##"<<j<<"\n";
                if(j==0)
                {
                    G[u].emplace_back(T,lc);
                    G[u].emplace_back(T,rc);
                }
                else
                {
                    Gen(L,u,j,0);
                    Gen(R,u,j,1);
                }
                break;
            }
        }
    }
    cout<<cnt<<"\n";
    for(int i=1;i<=cnt;i++)
    {
        // cerr<<i<<": ";
        sort(G[i].begin(),G[i].end());
        G[i].erase(unique(G[i].begin(),G[i].end()),G[i].end());
        cout<<G[i].size()<<" ";
        for(auto [v,w]:G[i])
            cout<<v<<" "<<w<<" ";
        cout<<"\n";
    }
    Dfs(S,"");
    if(cnt>100) while(1);
    // for(int i=L;i<=R;i++)
    //     cerr<<i<<" "<<tong[i]<<"\n";
        // assert(tong[i]==1);
    return 0;
}

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

詳細信息

Test #1:

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

input:

5 7

output:

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

result:

ok ok

Test #2:

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

input:

10 27

output:

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

result:

ok ok

Test #3:

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

input:

5 13

output:

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

result:

ok ok

Test #4:

score: 0
Accepted
time: 46ms
memory: 7756kb

input:

1 1000000

output:

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

result:

ok ok

Test #5:

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

input:

1 1

output:

2
1 2 1 
0 

result:

ok ok

Test #6:

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

input:

7 9

output:

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

result:

ok ok

Test #7:

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

input:

3 7

output:

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

result:

ok ok

Test #8:

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

input:

1 5

output:

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

result:

ok ok

Test #9:

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

input:

1 4

output:

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

result:

ok ok

Test #10:

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

input:

8 9

output:

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

result:

ok ok

Test #11:

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

input:

7 51

output:

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

result:

ok ok

Test #12:

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

input:

51 79

output:

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

result:

ok ok

Test #13:

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

input:

92 99

output:

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

result:

ok ok

Test #14:

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

input:

27 36

output:

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

result:

ok ok

Test #15:

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

input:

55 84

output:

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

result:

ok ok

Test #16:

score: 0
Accepted
time: 27ms
memory: 6060kb

input:

297208 929600

output:

57
2 3 1 38 1 
0 
2 4 0 21 1 
2 20 1 22 0 
2 2 0 2 1 
2 5 0 5 1 
2 6 0 6 1 
2 7 0 7 1 
2 8 0 8 1 
2 9 0 9 1 
2 10 0 10 1 
2 11 0 11 1 
2 12 0 12 1 
2 13 0 13 1 
2 14 0 14 1 
2 15 0 15 1 
2 16 0 16 1 
2 17 0 17 1 
2 18 0 18 1 
2 19 0 19 1 
2 20 0 20 1 
1 23 1 
2 18 1 24 0 
2 17 1 25 0 
2 16 1 26 0 
1...

result:

ok ok

Test #17:

score: 0
Accepted
time: 14ms
memory: 6324kb

input:

45728 589156

output:

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

result:

ok ok

Test #18:

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

input:

129152 138000

output:

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

result:

ok ok

Test #19:

score: 0
Accepted
time: 16ms
memory: 5716kb

input:

245280 654141

output:

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

result:

ok ok

Test #20:

score: 0
Accepted
time: 5ms
memory: 5676kb

input:

202985 296000

output:

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

result:

ok ok

Test #21:

score: 0
Accepted
time: 21ms
memory: 6732kb

input:

438671 951305

output:

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

result:

ok ok

Test #22:

score: 0
Accepted
time: 15ms
memory: 6588kb

input:

425249 739633

output:

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

result:

ok ok

Test #23:

score: 0
Accepted
time: 16ms
memory: 5400kb

input:

551207 961718

output:

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

result:

ok ok

Test #24:

score: 0
Accepted
time: 24ms
memory: 5868kb

input:

114691 598186

output:

55
4 3 1 32 1 54 1 55 1 
0 
1 4 1 
1 5 1 
2 6 0 19 1 
2 18 1 20 0 
2 2 0 2 1 
2 7 0 7 1 
2 8 0 8 1 
2 9 0 9 1 
2 10 0 10 1 
2 11 0 11 1 
2 12 0 12 1 
2 13 0 13 1 
2 14 0 14 1 
2 15 0 15 1 
2 16 0 16 1 
2 17 0 17 1 
2 18 0 18 1 
2 17 1 21 0 
2 16 1 22 0 
2 15 1 23 0 
2 14 1 24 0 
2 13 1 25 0 
2 12 1 ...

result:

ok ok

Test #25:

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

input:

234654 253129

output:

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

result:

ok ok

Test #26:

score: 0
Accepted
time: 3ms
memory: 5908kb

input:

554090 608599

output:

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

result:

ok ok

Extra Test:

score: 0
Extra Test Passed