QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#819787 | #9891. Traveler | rotcar07 | AC ✓ | 41ms | 3700kb | C++23 | 764b | 2024-12-18 17:28:34 | 2024-12-18 17:28:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
bool vis[100005];
inline void solve(){
int n;cin>>n;
memset(vis,0,sizeof(*vis)*(n+1));vis[0]=1;
for(int p=1,w=0,z=0,pos=(1<<__lg(n))-1,sb=1<<__lg(max(n,2))-1;!vis[p];){
if(!w)w=1;else cout<<" ";
cout<<p;vis[p]=1;
if(p==(n>>1))z=1;
if((p==pos||p==(pos>>1))&&!vis[sb^p]){
p^=sb;z=0;continue;
}
auto f=[&](int x)->bool {return x<=n&&!vis[x]?p=x:0;};
if(!z)f(p-1)||f(p<<1);
else{
if(p&1&&!vis[p>>1])p>>=1;
else f(p<<1|1)||f(p<<1)||f(p-1);
}
}
cout<<'\n';
}
int main(){
std::ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T;cin>>T;
while(T--) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
2 2 9
output:
1 2 1 2 4 9 8 7 3 6 5
result:
ok ok 2 cases.
Test #2:
score: 0
Accepted
time: 41ms
memory: 3700kb
input:
999 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
output:
1 1 2 1 3 2 1 3 2 4 1 3 2 5 4 1 3 6 5 2 4 1 3 7 6 5 2 4 1 2 4 8 7 3 6 5 1 2 4 9 8 7 3 6 5 1 2 4 3 7 6 5 10 9 8 1 2 4 3 7 6 5 11 10 9 8 1 2 4 3 7 6 12 11 5 10 9 8 1 2 4 3 7 6 13 12 11 5 10 9 8 1 2 4 3 7 14 13 6 12 11 5 10 9 8 1 2 4 3 7 15 14 13 6 12 11 5 10 9 8 1 2 4 3 6 5 10 9 8 16 15 7 14 13 12 11 ...
result:
ok ok 999 cases.
Extra Test:
score: 0
Extra Test Passed