QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343495#8174. Set Constructionucup-team004#WA 3ms3844kbC++202.3kb2024-03-02 17:40:342024-03-02 17:40:34

Judging History

你现在查看的是最新测评结果

  • [2024-03-02 17:40:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3844kb
  • [2024-03-02 17:40:34]
  • 提交

answer

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


typedef long long ll;

vector<ll> calc(int k,int c,int d,int e){
    assert(e>=2);
    if(k==3&&e==4)
        return {0,1,2,3,5,7};
    if(k==3&&e==3)
        return {0,1,2,3,7};
    vector<ll>ret;
    ret.push_back(0);
    ret.push_back(1);
    --e;
    while(e<c)
        --c,++d;
    int u=e/c,v=(e+c-1)/c;
    assert(v<=d);
    ll x=0;
    for(int j=1;j<=1+d-v;++j)
        x+=1ll<<(k-j);
    ret.push_back(x);
    vector<int>dis(c+1);

    for(int i=1;i<=c;++i){
        dis[i]=(e+i-1)/c;
        x+=1ll<<(i-1);
        ll y=x;
        for(int j=1;j<=dis[i];++j){
            ret.push_back(y);
            y+=1ll<<(k-(1+j+d-v));
        }
    }
    
    return ret;
}

vector<ll> solve(int n,int m){
    if(m==1ll<<n){
        vector<ll>ret(m);
        iota(ret.begin(),ret.end(),0);
        return ret;
    }
    if(m==2)
        return {0,(1ll<<n)-1};
    if(m==3)
        return {0,1,(1ll<<n)-1};
    if(n==2)
        return {0,1,3};
    if(n==5&&m==15)
        return {0,1,2,3,7,8,9,10,11,15,24,25,26,27,31};
    for(int i=1;i<n-1;++i){
        int k=n-i+1;
        int c=k/2,d=k-c;
        int e=c*d;
        if(k==3)
            e=4;
        int res=-1;
        if(m<=e+2*(i*(i+1)/2-1))
            res=min((m-1)/2,i*(i+1)/2);
        if(m>=2*(1ll<<i) && m <= e + 2*(1ll<<i)-2)
            res=1<<i;
        if(e+2>=m){
            auto v=calc(k,c,d,m-2);
            for(auto&t:v)
                t=(t>>1<<i)+(t&1)*((1ll<<i)-1);
            return v;
        }
        if(res<0)
            continue;
        auto v=solve(i,res);
        //if(res*2>m)
        //    cerr<<res<<' '<<m<<endl;
        //assert(res*2<=m);
        int ne=m-2*res+2;
        auto u=calc(k,c,d,ne);
        vector<ll>ret;
        for(auto&t:u)
            if(t&1)
                ret.push_back((t>>1<<i)+(1ll<<i)-1);
            else
                for(auto&s:v)
                    if(s!=(1<<i)-1)
                        ret.push_back((t>>1<<i)+s);
        return ret;
    }
    return {};
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int T;
    for(cin>>T; T --> 0; ){
        int n,m;
        cin>>n>>m;
        auto ans=solve(n,m);
        for(int i=0;i<m;++i)
            cout<<ans[i]<<" \n"[i==m-1];
    }
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

input:

3
3 5
4 8
60 2

output:

0 1 2 3 7
0 1 2 3 12 13 14 15
0 1152921504606846975

result:

ok AC

Test #2:

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

input:

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

output:

0 63
0 1 63
0 1 62 63
0 1 60 61 63
0 1 56 57 59 63
0 1 48 49 51 55 63
0 1 48 49 51 59 55 63
0 1 48 49 57 51 59 55 63
0 1 32 33 49 35 51 39 55 63
0 1 32 33 49 35 51 59 39 55 63
0 1 2 3 32 33 34 35 51 39 55 63
0 1 2 3 5 7 48 49 50 51 53 55 63
0 1 2 3 5 7 32 33 34 35 37 39 47 63
0 1 3 4 5 7 15 16 17 19...

result:

ok AC

Test #3:

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

input:

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

output:

0 1 96 97 113 121 99 115 123 103 119 127
0 1 64 65 97 113 67 99 115 71 103 119 127
0 1 64 65 97 113 67 99 115 123 71 103 119 127
0 1 2 3 64 65 66 67 99 71 103 119 79 111 127
0 1 2 3 4 5 6 7 120 121 122 123 124 125 126 127
0 1 2 3 4 5 6 7 112 113 114 115 116 117 118 119 127
0 1 2 3 4 5 6 7 96 97 98 9...

result:

ok AC

Test #4:

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

input:

30
8 15
8 16
8 17
8 18
8 19
8 20
8 21
8 22
8 23
8 24
8 25
8 26
8 27
8 28
8 29
8 30
8 31
8 32
8 33
8 34
8 35
8 36
9 2
9 3
9 4
9 5
9 6
9 7
9 8
9 9

output:

0 1 192 193 225 241 195 227 243 199 231 247 207 239 255
0 1 128 129 193 225 131 195 227 135 199 231 143 207 239 255
0 1 128 129 193 225 131 195 227 135 199 231 247 143 207 239 255
0 1 128 129 193 225 131 195 227 243 135 199 231 247 143 207 239 255
0 1 2 3 4 5 6 7 192 193 194 195 196 197 198 199 207 ...

result:

ok AC

Test #5:

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

input:

30
9 10
9 11
9 12
9 13
9 14
9 15
9 16
9 17
9 18
9 19
9 20
9 21
9 22
9 23
9 24
9 25
9 26
9 27
9 28
9 29
9 30
9 31
9 32
9 33
9 34
9 35
9 36
9 37
9 38
9 39

output:

0 1 480 481 483 499 487 503 495 511
0 1 480 481 497 483 499 487 503 495 511
0 1 448 449 481 451 483 455 487 463 495 511
0 1 448 449 481 451 483 455 487 503 463 495 511
0 1 448 449 481 451 483 499 455 487 503 463 495 511
0 1 448 449 481 497 451 483 499 455 487 503 463 495 511
0 1 384 385 449 481 387 ...

result:

ok AC

Test #6:

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

input:

6
9 40
9 41
9 42
9 43
9 44
9 45

output:

0 1 2 3 4 5 6 7 15 16 17 18 19 20 21 22 23 31 63 256 257 258 259 260 261 262 263 271 272 273 274 275 276 277 278 279 287 319 383 511
0 1 2 3 4 5 6 7 15 16 17 18 19 20 21 22 23 31 47 63 384 385 386 387 388 389 390 391 399 400 401 402 403 404 405 406 407 415 431 447 511
0 1 2 3 4 5 6 7 15 16 17 18 19 ...

result:

ok AC

Test #7:

score: -100
Wrong Answer
time: 3ms
memory: 3660kb

input:

30
60 1801
60 1802
60 1803
60 1804
60 1805
60 1806
60 1807
60 1808
60 1809
60 1810
60 1811
60 1812
60 1813
60 1814
60 1815
60 1816
60 1817
60 1818
60 1819
60 1820
60 1821
60 1822
60 1823
60 1824
60 1825
60 1826
60 1827
60 1828
60 1829
60 1830

output:

0 1 2 3 7 8 9 10 11 15 23 31 32 33 34 35 39 40 41 42 43 47 55 63 127 768 769 770 771 775 776 777 778 779 783 791 799 800 801 802 803 807 808 809 810 811 815 823 831 895 1023 12288 12289 12290 12291 12295 12296 12297 12298 12299 12303 12311 12319 12320 12321 12322 12323 12327 12328 12329 12330 12331 ...

result:

wrong answer Outputs are not distinct