QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#304709 | #8004. Bit Component | ucup-team987# | AC ✓ | 30ms | 34088kb | C++20 | 4.0kb | 2024-01-14 00:46:05 | 2024-01-14 00:46:05 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int tm;
int vis[2<<17][20];
const int dir[5]={0,1,0,-1};
bool check(vector<int>ans)
{
int N=ans.size();
int pcsum=0;
{//perm
vector<bool>vis(N+1);
for(int v:ans)
{
if(v<=0||v>N)return false;
if(vis[v])return false;
vis[v]=true;
pcsum+=__builtin_popcount(v);
}
}
tm++;
int sx=0,sy=0;
while(!(ans[sx]>>sy&1))sy++;
vis[sx][sy]=tm;
vector<pair<int,int> >Q;
Q.push_back(make_pair(sx,sy));
for(int i=0;i<Q.size();i++)
{
int x=Q[i].first,y=Q[i].second;
for(int r=0;r<4;r++)
{
int tx=x+dir[r],ty=y+dir[r+1];
if(tx<0||ty<0||tx>=N||vis[tx][ty]==tm)continue;
if(!(ans[tx]>>ty&1))continue;
vis[tx][ty]=tm;
Q.push_back(make_pair(tx,ty));
}
}
return Q.size()==pcsum;
}
vector<int>gray(int N)
{//[0,N=2^k)
int k=0;
while(N>>k+1)k++;
assert((1<<k)==N);
vector<int>ans(N);
for(int i=0;i<N;i++)ans[i]=i^i>>1;
return ans;
}
vector<int>solve(int N)
{
int k=0;
while(N>>k+1)k++;
if((1<<k+1)==N+1)
{
vector<int>ret=gray(N+1);
assert(ret[0]==0);
ret.erase(ret.begin());
return ret;
}
if(k<2||!(N>>k-1&1)||!(N>>k-2&1))return vector<int>();
vector<int>ans=gray(1<<k);
assert(ans[0]==0);
ans.erase(ans.begin());
assert(ans.back()==(1<<k-1));
{
vector<int>t=gray(1<<k-2);
reverse(t.begin(),t.end());
assert(t.back()==0);
t.pop_back();
ans.push_back(1<<k|1<<k-1);
for(int v:t)ans.push_back(1<<k|1<<k-1|v);
assert(ans.back()==(1<<k|1<<k-1|1<<0));
}
const int base=1<<k|1<<k-1|1<<k-2;
//ans.push_back(base);
{
vector<int>t=gray(1<<k-1);
assert(t[0]==0);
t.erase(t.begin());
for(int v:t)
{
v|=1<<k;
ans.push_back(v);
v|=1<<k-1;
if(v<=N&&(v&base)==base&&v>base)ans.push_back(v);
}
}
ans.push_back(base);
ans.push_back(1<<k);
return ans;
}
vector<int>solve2(int N)
{
vector<int>t=solve(N);
if(!t.empty())return t;
if(t.empty())
{
t=solve(N+1);
if(!t.empty()&&t[t.size()-2]==N+1)
{
t.erase(t.begin()+t.size()-2);
if(check(t))return t;
}
}
return vector<int>();
}
vector<int>solve3(int N)
{
int k=0;
while(N>>k+1)k++;
if((1<<k+1)==N+1)
{
vector<int>ret=gray(N+1);
assert(ret[0]==0);
ret.erase(ret.begin());
return ret;
}
if(k<2)return vector<int>();
const int base=1<<k|1<<k-1;
if(N<=base)return vector<int>();
vector<int>G=gray(1<<k-1);
vector<int>ans;
ans.reserve(N);
{//00
for(int i=1;i<G.size();i++)ans.push_back(G[i]);
}
{//01
ans.push_back(1<<k-1|G[G.size()-1]);
ans.push_back(1<<k-1);
for(int i=G.size()-2;i>=1;i--)ans.push_back(1<<k-1|G[i]);
}
ans.push_back(base+1);
{//10
for(int i=1;i<=G.size();i++)
{
int v=G[i%G.size()];
v|=1<<k;
ans.push_back(v);
v|=1<<k-1;
if(v<=N&&v!=base+1)ans.push_back(v);
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
for(int N=1;N<=200000;N++)
{
/*
vector<int>t1=solve(N),t2=solve2(N),t3=solve3(N);
if(!t1.empty())assert(check(t1));
if(!t2.empty())assert(check(t2));
if(!t3.empty())assert(check(t3));
if((t1.empty()&&t2.empty())!=t3.empty())
{
assert(!t3.empty());
for(int k=20;k--;)cout<<(N>>k&1);
cout<<endl;
}
*/
/*
vector<int>t=solve(N);
if(t.empty())
{
t=solve(N+1);
if(!t.empty()&&t[t.size()-2]==N+1)
{
cout<<"try on "<<N<<" = ";
for(int k=20;k--;)cout<<(N>>k&1);
cout<<endl;
t.erase(t.begin()+t.size()-2);
for(int v:t)
{
for(int k=20;k--;)cout<<(v>>k&1);
cout<<endl;
}
if(check(t))cout<<"FN ans"<<endl;
}
}
else if(0&&!check(t))
{
cout<<"WA on "<<N<<endl;
for(int v:t)
{
for(int k=20;k--;)cout<<(v>>k&1);
cout<<endl;
}
return 1;
}
*/
}
int N;cin>>N;
vector<int>t=solve3(N);
if(t.empty())cout<<"NO\n";
else
{
assert(check(t));
cout<<"YES\n";
for(int i=0;i<t.size();i++)cout<<t[i]<<(i+1==t.size()?"\n":" ");
}
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3444kb
input:
1
output:
YES 1
result:
ok answer is 1
Test #2:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
2
output:
NO
result:
ok answer is 0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
3
output:
YES 1 3 2
result:
ok answer is 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
4
output:
NO
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
5
output:
NO
result:
ok answer is 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 3452kb
input:
6
output:
NO
result:
ok answer is 0
Test #7:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
7
output:
YES 1 3 2 6 7 5 4
result:
ok answer is 1
Test #8:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
8
output:
NO
result:
ok answer is 0
Test #9:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
9
output:
NO
result:
ok answer is 0
Test #10:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
10
output:
NO
result:
ok answer is 0
Test #11:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
11
output:
NO
result:
ok answer is 0
Test #12:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
12
output:
NO
result:
ok answer is 0
Test #13:
score: 0
Accepted
time: 1ms
memory: 3388kb
input:
13
output:
YES 1 3 2 6 4 7 5 13 9 11 10 8 12
result:
ok answer is 1
Test #14:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
14
output:
YES 1 3 2 6 4 7 5 13 9 11 10 14 8 12
result:
ok answer is 1
Test #15:
score: 0
Accepted
time: 0ms
memory: 3452kb
input:
15
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8
result:
ok answer is 1
Test #16:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
16
output:
NO
result:
ok answer is 0
Test #17:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
17
output:
NO
result:
ok answer is 0
Test #18:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
23
output:
NO
result:
ok answer is 0
Test #19:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
24
output:
NO
result:
ok answer is 0
Test #20:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
25
output:
YES 1 3 2 6 7 5 4 12 8 13 15 14 10 11 9 25 17 19 18 22 23 21 20 16 24
result:
ok answer is 1
Test #21:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
26
output:
YES 1 3 2 6 7 5 4 12 8 13 15 14 10 11 9 25 17 19 18 26 22 23 21 20 16 24
result:
ok answer is 1
Test #22:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
27
output:
YES 1 3 2 6 7 5 4 12 8 13 15 14 10 11 9 25 17 19 27 18 26 22 23 21 20 16 24
result:
ok answer is 1
Test #23:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
40
output:
NO
result:
ok answer is 0
Test #24:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
53
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 16 25 27 26 30 31 29 28 20 21 23 22 18 19 17 49 33 35 51 34 50 38 39 37 53 36 52 44 45 47 46 42 43 41 40 32 48
result:
ok answer is 1
Test #25:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
93
output:
NO
result:
ok answer is 0
Test #26:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
105
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 32 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 97 65 67 99 66 98 70 102 71 103 69 101 68 100 76 77 79 78 74 75 73 105 72 104 88 89 91 90 94 95 93 92 84 85 87 86 82...
result:
ok answer is 1
Test #27:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
132
output:
NO
result:
ok answer is 0
Test #28:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
221
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 64 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 1...
result:
ok answer is 1
Test #29:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
373
output:
NO
result:
ok answer is 0
Test #30:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
473
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #31:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
513
output:
NO
result:
ok answer is 0
Test #32:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
934
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #33:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
1356
output:
NO
result:
ok answer is 0
Test #34:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
1651
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #35:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
2263
output:
NO
result:
ok answer is 0
Test #36:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
3330
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #37:
score: 0
Accepted
time: 1ms
memory: 3440kb
input:
4375
output:
NO
result:
ok answer is 0
Test #38:
score: 0
Accepted
time: 2ms
memory: 4496kb
input:
7989
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #39:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
10925
output:
NO
result:
ok answer is 0
Test #40:
score: 0
Accepted
time: 3ms
memory: 5308kb
input:
14097
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #41:
score: 0
Accepted
time: 0ms
memory: 3444kb
input:
16893
output:
NO
result:
ok answer is 0
Test #42:
score: 0
Accepted
time: 7ms
memory: 7252kb
input:
28913
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #43:
score: 0
Accepted
time: 1ms
memory: 3436kb
input:
40092
output:
NO
result:
ok answer is 0
Test #44:
score: 0
Accepted
time: 8ms
memory: 11196kb
input:
54980
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #45:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
88104
output:
NO
result:
ok answer is 0
Test #46:
score: 0
Accepted
time: 14ms
memory: 19272kb
input:
106284
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #47:
score: 0
Accepted
time: 1ms
memory: 3432kb
input:
152797
output:
NO
result:
ok answer is 0
Test #48:
score: 0
Accepted
time: 30ms
memory: 34088kb
input:
200000
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #49:
score: 0
Accepted
time: 1ms
memory: 3916kb
input:
3073
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #50:
score: 0
Accepted
time: 0ms
memory: 5648kb
input:
16383
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #51:
score: 0
Accepted
time: 3ms
memory: 7912kb
input:
32767
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #52:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
399
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 115 ...
result:
ok answer is 1
Test #53:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
5757
output:
NO
result:
ok answer is 0
Test #54:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
179
output:
NO
result:
ok answer is 0
Test #55:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
228
output:
YES 1 3 2 6 7 5 4 12 13 15 14 10 11 9 8 24 25 27 26 30 31 29 28 20 21 23 22 18 19 17 16 48 49 51 50 54 55 53 52 60 61 63 62 58 59 57 56 40 41 43 42 46 47 45 44 36 37 39 38 34 35 33 32 96 64 97 99 98 102 103 101 100 108 109 111 110 106 107 105 104 120 121 123 122 126 127 125 124 116 117 119 118 114 1...
result:
ok answer is 1
Extra Test:
score: 0
Extra Test Passed