結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
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 121 ms
15,104 KB
testcase_13 AC 114 ms
15,232 KB
testcase_14 AC 135 ms
15,104 KB
testcase_15 AC 115 ms
15,104 KB
testcase_16 AC 83 ms
11,904 KB
testcase_17 AC 78 ms
11,776 KB
testcase_18 AC 105 ms
14,208 KB
testcase_19 AC 118 ms
15,104 KB
testcase_20 AC 112 ms
14,976 KB
testcase_21 AC 122 ms
14,976 KB
testcase_22 AC 62 ms
9,856 KB
testcase_23 AC 116 ms
15,232 KB
testcase_24 AC 66 ms
10,112 KB
testcase_25 AC 121 ms
15,104 KB
testcase_26 AC 100 ms
13,056 KB
testcase_27 AC 119 ms
14,976 KB
testcase_28 AC 93 ms
12,416 KB
testcase_29 AC 124 ms
15,104 KB
testcase_30 AC 87 ms
11,520 KB
testcase_31 AC 116 ms
14,976 KB
testcase_32 AC 108 ms
14,336 KB
testcase_33 AC 114 ms
15,104 KB
testcase_34 AC 76 ms
11,008 KB
testcase_35 AC 120 ms
14,976 KB
testcase_36 AC 110 ms
14,208 KB
testcase_37 AC 122 ms
15,104 KB
testcase_38 AC 102 ms
13,696 KB
testcase_39 AC 125 ms
15,104 KB
testcase_40 AC 104 ms
13,056 KB
testcase_41 AC 117 ms
15,232 KB
testcase_42 AC 85 ms
12,160 KB
testcase_43 AC 124 ms
15,104 KB
testcase_44 AC 61 ms
9,472 KB
testcase_45 AC 117 ms
14,976 KB
testcase_46 AC 103 ms
13,952 KB
testcase_47 AC 116 ms
14,976 KB
testcase_48 AC 71 ms
10,624 KB
testcase_49 AC 113 ms
14,976 KB
testcase_50 AC 65 ms
10,368 KB
testcase_51 AC 108 ms
15,104 KB
testcase_52 AC 91 ms
13,312 KB
testcase_53 AC 115 ms
15,104 KB
testcase_54 AC 112 ms
15,104 KB
testcase_55 AC 113 ms
15,232 KB
testcase_56 AC 113 ms
15,104 KB
testcase_57 AC 58 ms
9,472 KB
testcase_58 AC 77 ms
11,392 KB
testcase_59 AC 71 ms
11,008 KB
testcase_60 AC 61 ms
9,856 KB
testcase_61 AC 56 ms
9,472 KB
testcase_62 AC 95 ms
13,056 KB
testcase_63 AC 2 ms
6,944 KB
testcase_64 AC 1 ms
6,940 KB
testcase_65 AC 1 ms
6,940 KB
testcase_66 AC 2 ms
6,940 KB
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 10 ms
26,788 KB
testcase_70 AC 8 ms
26,792 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 AC 10 ms
26,780 KB
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 9 ms
26,768 KB
testcase_83 WA -
testcase_84 AC 10 ms
26,792 KB
testcase_85 AC 9 ms
26,800 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 AC 10 ms
26,880 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 AC 10 ms
26,656 KB
testcase_92 WA -
testcase_93 AC 10 ms
26,720 KB
testcase_94 WA -
testcase_95 WA -
testcase_96 WA -
testcase_97 AC 10 ms
26,832 KB
testcase_98 AC 10 ms
26,768 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;


    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++){
                
            }
            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()));

    }
    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){
        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