結果
問題 | No.2732 Similar Permutations |
ユーザー |
|
提出日時 | 2024-04-19 23:07:45 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,258 bytes |
コンパイル時間 | 2,388 ms |
コンパイル使用メモリ | 217,712 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-10-11 17:20:31 |
合計ジャッジ時間 | 25,267 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 62 WA * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; if(N == 1){cout << -1 << endl; return 0;} vector<pair<int,int>> A(N); for(int i=0; i<N; i++) cin >> A.at(i).first,A.at(i).second = i; sort(A.begin(),A.end()); set<int> idx; for(int i=1; i<=N; i++) idx.insert(i); int swap1 = -1,swap2 = -1; vector<int> answer(N); for(int i=0; i<N-1; i++){ auto[a1,pos1] = A.at(i); auto[a2,pos2] = A.at(i+1); if(a1 == a2){ swap1 = pos1,swap2 = pos2; answer.at(pos1) = 1,answer.at(pos2) = 2; idx.erase(1); idx.erase(2); break; } } if(swap1 == -1){ for(int d=0; d<20; d++) for(int d2=d+1; d2<20; d2++){ if(N < (1<<d2) || swap1 != -1) break; vector<int> ok(4,-1); for(int i=0; i<N; i++){ auto[a,pos] = A.at(i); int p = (a&(1<<d2))/(1<<d2)*2+(a&(1<<d))/(1<<d); ok.at(p) = pos; } for(int p=0; p<3; p++) for(int p2=p+1; p2<4; p2++){ if(ok.at(p) == -1 || ok.at(p2) == -1 || swap1 != -1) continue; if(p+p2 == 3){ swap1 = ok.at(p); swap2 = ok.at(p2); answer.at(ok.at(p)) = 1<<d; answer.at(ok.at(p2)) = 1<<d2; idx.erase(1<<d); idx.erase(1<<d2); } else{ if((1<<d2)+(1<<d) > N) continue; swap1 = ok.at(p); swap2 = ok.at(p2); answer.at(ok.at(p)) = (1<<d)+(1<<d2); answer.at(ok.at(p2)) = 1<<d2; idx.erase(answer.at(ok.at(p))); idx.erase(1<<d2); } } } } if(swap1 == -1){cout << -1 << endl; return 0;} for(auto &a : answer) if(a == 0) a = *idx.begin(),idx.erase(idx.begin()); for(int i=0; i<N; i++) cout << answer.at(i) << (i==N-1?"\n":" "); for(int i=0; i<N; i++){ if(i != swap1 && i != swap2) cout << answer.at(i) << (i==N-1?"\n":" "); if(i == swap1) cout << answer.at(swap2) << (i==N-1?"\n":" "); if(i == swap2) cout << answer.at(swap1) << (i==N-1?"\n":" "); } }