結果

問題 No.2732 Similar Permutations
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-19 23:43:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,461 bytes
コンパイル時間 3,043 ms
コンパイル使用メモリ 216,600 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-04-19 23:44:17
合計ジャッジ時間 21,636 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
26,752 KB
testcase_01 AC 18 ms
26,752 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 120 ms
14,976 KB
testcase_13 AC 117 ms
14,976 KB
testcase_14 AC 115 ms
14,976 KB
testcase_15 AC 116 ms
15,104 KB
testcase_16 AC 79 ms
11,776 KB
testcase_17 AC 79 ms
11,776 KB
testcase_18 AC 108 ms
14,080 KB
testcase_19 AC 135 ms
15,104 KB
testcase_20 AC 112 ms
14,976 KB
testcase_21 AC 119 ms
15,104 KB
testcase_22 AC 64 ms
9,984 KB
testcase_23 AC 119 ms
15,104 KB
testcase_24 AC 69 ms
10,240 KB
testcase_25 AC 118 ms
15,104 KB
testcase_26 AC 96 ms
13,056 KB
testcase_27 AC 117 ms
15,104 KB
testcase_28 AC 90 ms
12,544 KB
testcase_29 AC 118 ms
15,104 KB
testcase_30 AC 82 ms
11,648 KB
testcase_31 AC 119 ms
15,104 KB
testcase_32 AC 114 ms
14,208 KB
testcase_33 AC 117 ms
15,104 KB
testcase_34 AC 76 ms
11,008 KB
testcase_35 AC 134 ms
14,976 KB
testcase_36 AC 107 ms
14,208 KB
testcase_37 AC 117 ms
15,104 KB
testcase_38 AC 105 ms
13,568 KB
testcase_39 AC 120 ms
15,104 KB
testcase_40 AC 99 ms
12,928 KB
testcase_41 AC 117 ms
15,232 KB
testcase_42 AC 89 ms
12,160 KB
testcase_43 AC 119 ms
14,976 KB
testcase_44 AC 61 ms
9,344 KB
testcase_45 AC 134 ms
15,104 KB
testcase_46 AC 106 ms
13,952 KB
testcase_47 AC 120 ms
15,104 KB
testcase_48 AC 73 ms
10,496 KB
testcase_49 AC 113 ms
14,976 KB
testcase_50 AC 67 ms
10,240 KB
testcase_51 AC 112 ms
15,104 KB
testcase_52 AC 93 ms
13,184 KB
testcase_53 AC 114 ms
15,104 KB
testcase_54 AC 114 ms
15,104 KB
testcase_55 AC 116 ms
14,976 KB
testcase_56 AC 116 ms
15,104 KB
testcase_57 AC 60 ms
9,472 KB
testcase_58 AC 82 ms
11,520 KB
testcase_59 AC 77 ms
11,136 KB
testcase_60 AC 67 ms
9,856 KB
testcase_61 AC 58 ms
9,344 KB
testcase_62 AC 109 ms
12,928 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
testcase_65 AC 1 ms
5,376 KB
testcase_66 AC 1 ms
5,376 KB
testcase_67 AC 18 ms
26,880 KB
testcase_68 AC 19 ms
26,624 KB
testcase_69 AC 19 ms
26,752 KB
testcase_70 AC 19 ms
26,752 KB
testcase_71 AC 19 ms
26,752 KB
testcase_72 AC 19 ms
26,624 KB
testcase_73 AC 19 ms
26,880 KB
testcase_74 AC 19 ms
26,752 KB
testcase_75 AC 18 ms
26,624 KB
testcase_76 AC 19 ms
26,752 KB
testcase_77 AC 19 ms
26,880 KB
testcase_78 AC 19 ms
26,752 KB
testcase_79 AC 18 ms
26,752 KB
testcase_80 AC 19 ms
26,880 KB
testcase_81 AC 19 ms
26,752 KB
testcase_82 AC 18 ms
26,752 KB
testcase_83 AC 19 ms
26,752 KB
testcase_84 AC 18 ms
26,752 KB
testcase_85 AC 19 ms
26,752 KB
testcase_86 AC 19 ms
26,752 KB
testcase_87 AC 18 ms
26,752 KB
testcase_88 AC 20 ms
26,752 KB
testcase_89 AC 19 ms
26,624 KB
testcase_90 AC 22 ms
26,752 KB
testcase_91 AC 21 ms
26,752 KB
testcase_92 AC 19 ms
26,624 KB
testcase_93 AC 18 ms
26,624 KB
testcase_94 AC 19 ms
26,880 KB
testcase_95 AC 18 ms
26,624 KB
testcase_96 AC 18 ms
26,752 KB
testcase_97 AC 18 ms
26,624 KB
testcase_98 AC 18 ms
26,624 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

random_device rnd;
mt19937 mt(rnd());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    double st = clock();
    
    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());

    if(N < 10){
        vector<vector<int>> M(1e6);
        vector<int> P(N);
        iota(P.begin(),P.end(),1);
        do{
            int Xor = 0;
            for(int i=0; i<N; i++) Xor ^= A.at(i).first+P.at(A.at(i).second);
            if(M.at(Xor).size()){
                for(int i=0; i<N; i++) cout << P.at(i) << " "; cout << endl;
                for(int i=0; i<N; i++) cout << M.at(Xor).at(i) << " "; cout << endl;
                return 0;
            }
            M.at(Xor) = P;
        }while(next_permutation(P.begin(),P.end()));
		cout << -1 << endl; return 0;
    }

    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){
        while(swap1 == -1){
            double no = clock();
            if((no-st)/CLOCKS_PER_SEC >= 1.8) break;
            int pos1 = mt()%N,pos2 = pos1;
            while(pos2 == pos1){pos2 = mt()%N;}

            auto[a1,p1] = A.at(pos1); auto[a2,p2] = A.at(pos2);
            for(int d=0; d<20; d++) for(int d2=d+1; d2<20; d2++){
                if(N > (1<<d2) || a1&(1<<d) || a2&(1<<d2) || a1&(1<<d2) || a2&(1<<d) || swap1 != -1) continue;
                swap1 = p1,swap2 = p2;
                answer.at(p1) = 1<<d; answer.at(p2) = 1<<d2;
                idx.erase(1<<d); 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":" ");
    }
}
0