結果
問題 | No.2732 Similar Permutations |
ユーザー | shobonvip |
提出日時 | 2024-04-19 23:19:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 3,520 bytes |
コンパイル時間 | 4,792 ms |
コンパイル使用メモリ | 279,520 KB |
実行使用メモリ | 15,716 KB |
最終ジャッジ日時 | 2024-10-11 17:54:22 |
合計ジャッジ時間 | 22,488 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
15,616 KB |
testcase_01 | AC | 8 ms
15,488 KB |
testcase_02 | AC | 33 ms
6,784 KB |
testcase_03 | AC | 59 ms
7,620 KB |
testcase_04 | AC | 21 ms
6,016 KB |
testcase_05 | AC | 16 ms
5,760 KB |
testcase_06 | AC | 9 ms
5,632 KB |
testcase_07 | AC | 45 ms
6,936 KB |
testcase_08 | AC | 23 ms
6,272 KB |
testcase_09 | AC | 12 ms
5,760 KB |
testcase_10 | AC | 101 ms
9,216 KB |
testcase_11 | AC | 11 ms
5,632 KB |
testcase_12 | AC | 104 ms
9,248 KB |
testcase_13 | AC | 105 ms
9,372 KB |
testcase_14 | AC | 103 ms
9,372 KB |
testcase_15 | AC | 103 ms
9,216 KB |
testcase_16 | AC | 75 ms
8,124 KB |
testcase_17 | AC | 74 ms
8,192 KB |
testcase_18 | AC | 95 ms
8,988 KB |
testcase_19 | AC | 103 ms
9,244 KB |
testcase_20 | AC | 102 ms
9,320 KB |
testcase_21 | AC | 104 ms
9,372 KB |
testcase_22 | AC | 60 ms
7,808 KB |
testcase_23 | AC | 104 ms
9,372 KB |
testcase_24 | AC | 62 ms
7,680 KB |
testcase_25 | AC | 103 ms
9,368 KB |
testcase_26 | AC | 85 ms
8,704 KB |
testcase_27 | AC | 103 ms
9,368 KB |
testcase_28 | AC | 82 ms
8,448 KB |
testcase_29 | AC | 103 ms
9,368 KB |
testcase_30 | AC | 74 ms
8,200 KB |
testcase_31 | AC | 103 ms
9,372 KB |
testcase_32 | AC | 96 ms
9,000 KB |
testcase_33 | AC | 104 ms
9,372 KB |
testcase_34 | AC | 69 ms
7,936 KB |
testcase_35 | AC | 104 ms
9,368 KB |
testcase_36 | AC | 96 ms
9,128 KB |
testcase_37 | AC | 104 ms
9,368 KB |
testcase_38 | AC | 91 ms
8,832 KB |
testcase_39 | AC | 104 ms
9,240 KB |
testcase_40 | AC | 86 ms
8,584 KB |
testcase_41 | AC | 102 ms
9,216 KB |
testcase_42 | AC | 79 ms
8,192 KB |
testcase_43 | AC | 103 ms
9,368 KB |
testcase_44 | AC | 56 ms
7,476 KB |
testcase_45 | AC | 102 ms
9,364 KB |
testcase_46 | AC | 92 ms
8,960 KB |
testcase_47 | AC | 100 ms
9,368 KB |
testcase_48 | AC | 63 ms
7,808 KB |
testcase_49 | AC | 99 ms
9,492 KB |
testcase_50 | AC | 60 ms
7,680 KB |
testcase_51 | AC | 93 ms
9,236 KB |
testcase_52 | AC | 79 ms
8,644 KB |
testcase_53 | AC | 104 ms
9,388 KB |
testcase_54 | AC | 104 ms
9,500 KB |
testcase_55 | AC | 104 ms
9,376 KB |
testcase_56 | AC | 104 ms
9,248 KB |
testcase_57 | AC | 55 ms
7,368 KB |
testcase_58 | AC | 74 ms
8,192 KB |
testcase_59 | AC | 69 ms
8,064 KB |
testcase_60 | AC | 60 ms
7,552 KB |
testcase_61 | AC | 53 ms
7,436 KB |
testcase_62 | AC | 86 ms
8,704 KB |
testcase_63 | AC | 8 ms
15,488 KB |
testcase_64 | AC | 8 ms
15,616 KB |
testcase_65 | AC | 8 ms
15,616 KB |
testcase_66 | AC | 8 ms
15,600 KB |
testcase_67 | AC | 8 ms
15,668 KB |
testcase_68 | AC | 8 ms
15,616 KB |
testcase_69 | AC | 8 ms
15,488 KB |
testcase_70 | AC | 8 ms
15,616 KB |
testcase_71 | AC | 8 ms
15,600 KB |
testcase_72 | AC | 8 ms
15,616 KB |
testcase_73 | AC | 8 ms
15,632 KB |
testcase_74 | AC | 8 ms
15,616 KB |
testcase_75 | AC | 8 ms
15,616 KB |
testcase_76 | AC | 8 ms
15,448 KB |
testcase_77 | AC | 7 ms
15,700 KB |
testcase_78 | AC | 8 ms
15,616 KB |
testcase_79 | AC | 8 ms
15,684 KB |
testcase_80 | AC | 8 ms
15,696 KB |
testcase_81 | AC | 7 ms
15,616 KB |
testcase_82 | AC | 8 ms
15,616 KB |
testcase_83 | AC | 8 ms
15,600 KB |
testcase_84 | AC | 8 ms
15,512 KB |
testcase_85 | AC | 8 ms
15,636 KB |
testcase_86 | AC | 8 ms
15,616 KB |
testcase_87 | AC | 8 ms
15,616 KB |
testcase_88 | AC | 8 ms
15,616 KB |
testcase_89 | AC | 8 ms
15,584 KB |
testcase_90 | AC | 8 ms
15,616 KB |
testcase_91 | AC | 8 ms
15,616 KB |
testcase_92 | AC | 8 ms
15,484 KB |
testcase_93 | AC | 8 ms
15,616 KB |
testcase_94 | AC | 8 ms
15,548 KB |
testcase_95 | AC | 8 ms
15,616 KB |
testcase_96 | AC | 8 ms
15,616 KB |
testcase_97 | AC | 8 ms
15,612 KB |
testcase_98 | AC | 7 ms
15,616 KB |
testcase_99 | AC | 7 ms
15,488 KB |
testcase_100 | AC | 8 ms
15,616 KB |
testcase_101 | AC | 8 ms
15,716 KB |
testcase_102 | AC | 8 ms
15,616 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ random_device seed_gen; mt19937 engine(seed_gen()); int n; cin >> n; vector<int> a(n); rep(i,0,n) cin >> a[i]; if (n <= 10){ vector<int> p(n); iota(p.begin(),p.end(),1); vector mem(1<<19,vector<int>(0)); do{ int r=0; rep(i,0,n)r^=a[i]+p[i]; if(mem[r].size()>0){ rep(i,0,n){ cout << mem[r][i] << ' '; } cout << '\n'; rep(i,0,n){ cout << p[i] << ' '; } cout << '\n'; return 0; } mem[r] = p; }while(next_permutation(p.begin(),p.end())); cout << -1 << '\n'; }else{ vector<int> mem(1<<19,-1); vector<int> p(n); iota(p.begin(), p.end(), 1); vector<mint> hash1(n); vector<mint> hash2(n); uniform_int_distribution<int> dist(0,998244353); rep(i,0,n){ hash1[i] = dist(engine); hash2[i] = dist(engine); } mint now1=0,now2=0; int val=0; rep(i,0,n){ now1 += hash1[i]*p[i]; now2 += hash2[i]*p[i]; val ^= p[i] + a[i]; } mem[val]=0; vector<pair<int,int>> sousa; uniform_int_distribution<int> dist2(0,n-1); set<pair<int,int>> st; int cnt = 0; while(true){ int u=dist2(engine); int v=dist2(engine); if(u==v)continue; now1 -= hash1[u]*p[u]; now2 -= hash2[u]*p[u]; now1 -= hash1[v]*p[v]; now2 -= hash2[v]*p[v]; now1 += hash1[u]*p[v]; now2 += hash2[u]*p[v]; now1 += hash1[v]*p[u]; now2 += hash2[v]*p[u]; val ^= p[u]+a[u]; val ^= p[v]+a[v]; val ^= p[u]+a[v]; val ^= p[v]+a[u]; sousa.push_back(pair(u,v)); swap(p[u],p[v]); if (st.find(pair(now1.val(),now2.val()))!=st.end()){ swap(p[u],p[v]); sousa.pop_back(); now1 += hash1[u]*p[u]; now2 += hash2[u]*p[u]; now1 += hash1[v]*p[v]; now2 += hash2[v]*p[v]; now1 -= hash1[u]*p[v]; now2 -= hash2[u]*p[v]; now1 -= hash1[v]*p[u]; now2 -= hash2[v]*p[u]; val ^= p[u]+a[u]; val ^= p[v]+a[v]; val ^= p[u]+a[v]; val ^= p[v]+a[u]; continue; } cnt++; st.insert(pair(now1.val(),now2.val())); if (mem[val]==-1){ mem[val]=cnt; }else{ { vector<int> q(n); iota(q.begin(),q.end(),1); rep(i,0,mem[val]){ auto[x,y] = sousa[i]; swap(q[x],q[y]); } rep(i,0,n){ cout << q[i] << ' '; } cout << '\n'; } { vector<int> q(n); iota(q.begin(),q.end(),1); rep(i,0,cnt){ auto[x,y] = sousa[i]; swap(q[x],q[y]); } rep(i,0,n){ cout << q[i] << ' '; } cout << '\n'; } return 0; } } } }