結果
問題 | No.2893 Minahoshi (Hard) |
ユーザー |
|
提出日時 | 2024-09-14 00:04:43 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,096 bytes |
コンパイル時間 | 2,891 ms |
コンパイル使用メモリ | 245,844 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-09-14 00:04:58 |
合計ジャッジ時間 | 14,509 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 WA * 20 RE * 17 |
ソースコード
#include<bits/stdc++.h> using namespace std; const int o=2e5+5; int n,K,pth[o],cnt,nxt[o];bool vis[o]; void dfs(int nw){ if(vis[nw]) return; vis[nw]=1;dfs(nw*2%(1<<K));dfs((nw*2+1)%(1<<K));pth[++cnt]=nw; } void solve() { scanf("%d",&n); K = 0; for(;(1<<K)+K-1<=n;++K); --K; dfs(0); for(int i=1,j=cnt;i<j;swap(pth[i++],pth[j--])); if(n==(1<<K)+K-1){ for(int i=1;i<K;++i) putchar(97); for(int i=1;i<=cnt;++i) putchar(97+pth[i]%2); cout << '\n'; return; } for(int i=0;i<(1<<(K+1));++i) vis[i]=0,nxt[i]=-1; for(int i=1;i<=cnt;++i) vis[pth[i]=(pth[i]<<1)|(pth[i+1]&1)]=1; for(int i=1;i<=cnt;++i) nxt[pth[i]]=pth[i%cnt+1]; for(int i=0;i<(1<<(K+1));++i) if(nxt[i]<0) nxt[i]=nxt[i^(1<<K)]^1; for(int i=0,t;i<(1<<(K+1));++i) if(!vis[i]){ for(t=i;!vis[t];t=nxt[t]) vis[t]=1,++cnt; swap(nxt[i],nxt[i^(1<<K)]); if(cnt+K>=n){ for(int j=K;j+1;--j) putchar(97+((nxt[i]>>j)&1)); for(int j=K+2,t=nxt[nxt[i]];j<=n;++j,t=nxt[t]) putchar(97+(t&1)); cout << '\n'; break; } } } int main(){ int t; scanf("%d", &t); while (t--) solve(); return 0; }