結果
| 問題 |
No.2893 Minahoshi (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-13 23:54:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,094 bytes |
| コンパイル時間 | 2,914 ms |
| コンパイル使用メモリ | 245,280 KB |
| 実行使用メモリ | 14,184 KB |
| 最終ジャッジ日時 | 2024-09-13 23:54:20 |
| 合計ジャッジ時間 | 9,590 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 WA * 21 RE * 4 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int o=1e6;
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;
}