結果

問題 No.2732 Similar Permutations
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-19 23:21:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 211,540 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-04-19 23:22:39
合計ジャッジ時間 41,977 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1,835 ms
5,376 KB
testcase_02 AC 32 ms
6,912 KB
testcase_03 AC 61 ms
9,856 KB
testcase_04 AC 19 ms
5,504 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 53 ms
8,320 KB
testcase_08 AC 22 ms
5,888 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 111 ms
14,720 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 122 ms
15,104 KB
testcase_13 AC 119 ms
15,232 KB
testcase_14 AC 123 ms
14,976 KB
testcase_15 AC 119 ms
15,104 KB
testcase_16 AC 84 ms
11,776 KB
testcase_17 AC 81 ms
11,520 KB
testcase_18 AC 109 ms
14,208 KB
testcase_19 AC 116 ms
15,104 KB
testcase_20 AC 117 ms
14,976 KB
testcase_21 AC 117 ms
15,104 KB
testcase_22 AC 64 ms
9,984 KB
testcase_23 AC 121 ms
15,104 KB
testcase_24 AC 67 ms
10,240 KB
testcase_25 AC 137 ms
15,104 KB
testcase_26 AC 98 ms
13,056 KB
testcase_27 AC 116 ms
14,976 KB
testcase_28 AC 92 ms
12,416 KB
testcase_29 AC 125 ms
15,104 KB
testcase_30 AC 83 ms
11,648 KB
testcase_31 AC 120 ms
15,232 KB
testcase_32 AC 117 ms
14,080 KB
testcase_33 AC 120 ms
15,104 KB
testcase_34 AC 78 ms
11,136 KB
testcase_35 AC 119 ms
14,976 KB
testcase_36 AC 111 ms
14,208 KB
testcase_37 AC 121 ms
15,104 KB
testcase_38 AC 106 ms
13,568 KB
testcase_39 AC 121 ms
14,976 KB
testcase_40 AC 115 ms
13,056 KB
testcase_41 AC 124 ms
15,232 KB
testcase_42 AC 87 ms
12,032 KB
testcase_43 AC 123 ms
15,104 KB
testcase_44 AC 60 ms
9,472 KB
testcase_45 AC 116 ms
14,976 KB
testcase_46 AC 108 ms
13,952 KB
testcase_47 AC 120 ms
14,976 KB
testcase_48 AC 69 ms
10,624 KB
testcase_49 AC 113 ms
15,104 KB
testcase_50 AC 68 ms
10,368 KB
testcase_51 AC 124 ms
15,104 KB
testcase_52 AC 93 ms
13,312 KB
testcase_53 AC 118 ms
15,104 KB
testcase_54 AC 119 ms
15,104 KB
testcase_55 AC 116 ms
15,104 KB
testcase_56 AC 135 ms
14,976 KB
testcase_57 AC 60 ms
9,472 KB
testcase_58 AC 82 ms
11,520 KB
testcase_59 AC 75 ms
11,136 KB
testcase_60 AC 63 ms
9,856 KB
testcase_61 AC 57 ms
9,344 KB
testcase_62 AC 96 ms
13,184 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
testcase_65 AC 2 ms
5,376 KB
testcase_66 AC 1 ms
5,376 KB
testcase_67 AC 1,872 ms
5,376 KB
testcase_68 AC 1,839 ms
5,376 KB
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 AC 2 ms
5,376 KB
testcase_77 AC 2 ms
5,376 KB
testcase_78 AC 2 ms
5,376 KB
testcase_79 AC 2 ms
5,376 KB
testcase_80 AC 2 ms
5,376 KB
testcase_81 WA -
testcase_82 AC 2 ms
5,376 KB
testcase_83 WA -
testcase_84 AC 2 ms
5,376 KB
testcase_85 AC 2 ms
5,376 KB
testcase_86 AC 2 ms
5,376 KB
testcase_87 AC 2 ms
5,376 KB
testcase_88 AC 1 ms
5,376 KB
testcase_89 AC 2 ms
5,376 KB
testcase_90 AC 2 ms
5,376 KB
testcase_91 AC 1 ms
5,376 KB
testcase_92 AC 1 ms
5,376 KB
testcase_93 AC 2 ms
5,376 KB
testcase_94 AC 1 ms
5,376 KB
testcase_95 AC 1 ms
5,376 KB
testcase_96 AC 1 ms
5,376 KB
testcase_97 AC 2 ms
5,376 KB
testcase_98 AC 1 ms
5,376 KB
testcase_99 AC 2 ms
5,376 KB
testcase_100 AC 2 ms
5,376 KB
testcase_101 AC 2 ms
5,376 KB
testcase_102 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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());

    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<<d) || a1&(1<<d2) || a2&(1<<d2) || 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