結果
問題 | No.2732 Similar Permutations |
ユーザー |
![]() |
提出日時 | 2024-04-25 16:53:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 88 ms / 2,000 ms |
コード長 | 1,502 bytes |
コンパイル時間 | 2,249 ms |
コンパイル使用メモリ | 198,472 KB |
最終ジャッジ日時 | 2025-02-21 08:59:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 101 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); //500000<=2^19-1=524287 //総XORは524287以下 //最初の10項を並び替えるだけで3628800通りの値が作れる int N, S, M; cin >> N; M = min(N, 10); vector<int> A(N); for (int i=0; i<N; i++) cin >> A[i]; vector<int> p(M); iota(p.begin(), p.end(), 1); vector<vector<int>> v(550000); if (N<=9){ do{ S = 0; for (int i=0; i<M; i++){ S ^= p[i]+A[i]; } if (v[S].size() == 0) v[S] = p; else{ for (auto x : p) cout << x << " "; cout << endl; for (auto x : v[S]) cout << x << " "; cout << endl; return 0; } } while(next_permutation(p.begin(), p.end())); cout << -1 << endl; return 0; } do{ S = 0; for (int i=0; i<M; i++){ S ^= (p[i]+A[i]); } if (v[S].size() == 0) v[S] = p; else{ for (auto x : p) cout << x << " "; for (int i=11; i<=N; i++) cout << i << " "; cout << endl; for (auto x : v[S]) cout << x << " "; for (int i=11; i<=N; i++) cout << i << " "; cout << endl; return 0; } } while(next_permutation(p.begin(), p.end())); return 0; }