結果

問題 No.2732 Similar Permutations
ユーザー GOTKAKOGOTKAKO
提出日時 2024-04-19 23:07:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,258 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 210,224 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-19 23:08:26
合計ジャッジ時間 26,953 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 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 124 ms
14,848 KB
testcase_13 AC 135 ms
14,976 KB
testcase_14 AC 132 ms
14,848 KB
testcase_15 AC 132 ms
14,848 KB
testcase_16 AC 92 ms
11,648 KB
testcase_17 AC 88 ms
11,520 KB
testcase_18 AC 124 ms
14,080 KB
testcase_19 AC 133 ms
14,976 KB
testcase_20 AC 146 ms
14,848 KB
testcase_21 AC 132 ms
14,976 KB
testcase_22 AC 73 ms
9,728 KB
testcase_23 AC 122 ms
14,976 KB
testcase_24 AC 71 ms
10,112 KB
testcase_25 AC 133 ms
14,848 KB
testcase_26 AC 101 ms
12,800 KB
testcase_27 AC 123 ms
14,848 KB
testcase_28 AC 102 ms
12,544 KB
testcase_29 AC 119 ms
14,848 KB
testcase_30 AC 95 ms
11,520 KB
testcase_31 AC 133 ms
14,976 KB
testcase_32 AC 115 ms
14,080 KB
testcase_33 AC 133 ms
14,848 KB
testcase_34 AC 86 ms
10,752 KB
testcase_35 AC 122 ms
14,976 KB
testcase_36 AC 107 ms
13,952 KB
testcase_37 AC 118 ms
14,848 KB
testcase_38 AC 101 ms
13,440 KB
testcase_39 AC 135 ms
14,976 KB
testcase_40 AC 101 ms
12,800 KB
testcase_41 AC 124 ms
14,976 KB
testcase_42 AC 98 ms
11,904 KB
testcase_43 AC 130 ms
15,104 KB
testcase_44 AC 64 ms
9,344 KB
testcase_45 AC 125 ms
14,848 KB
testcase_46 AC 117 ms
13,696 KB
testcase_47 AC 124 ms
14,976 KB
testcase_48 AC 75 ms
10,496 KB
testcase_49 AC 128 ms
14,848 KB
testcase_50 AC 76 ms
10,240 KB
testcase_51 AC 116 ms
14,976 KB
testcase_52 AC 100 ms
13,184 KB
testcase_53 AC 121 ms
14,848 KB
testcase_54 AC 120 ms
14,976 KB
testcase_55 AC 119 ms
14,976 KB
testcase_56 AC 119 ms
14,848 KB
testcase_57 AC 66 ms
9,344 KB
testcase_58 AC 91 ms
11,392 KB
testcase_59 AC 85 ms
11,008 KB
testcase_60 AC 71 ms
9,728 KB
testcase_61 AC 59 ms
9,088 KB
testcase_62 AC 107 ms
12,928 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
testcase_65 AC 1 ms
5,376 KB
testcase_66 AC 2 ms
5,376 KB
testcase_67 AC 2 ms
5,376 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 AC 2 ms
5,376 KB
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 2 ms
5,376 KB
testcase_83 WA -
testcase_84 WA -
testcase_85 AC 2 ms
5,376 KB
testcase_86 WA -
testcase_87 WA -
testcase_88 WA -
testcase_89 WA -
testcase_90 WA -
testcase_91 WA -
testcase_92 WA -
testcase_93 WA -
testcase_94 WA -
testcase_95 AC 2 ms
5,376 KB
testcase_96 WA -
testcase_97 AC 2 ms
5,376 KB
testcase_98 AC 2 ms
5,376 KB
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    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){
        for(int d=0; d<20; d++) for(int d2=d+1; d2<20; d2++){
            if(N < (1<<d2) || swap1 != -1) break;
            vector<int> ok(4,-1);
            for(int i=0; i<N; i++){
                auto[a,pos] = A.at(i);
                int p = (a&(1<<d2))/(1<<d2)*2+(a&(1<<d))/(1<<d);
                ok.at(p) = pos; 
            }
            for(int p=0; p<3; p++) for(int p2=p+1; p2<4; p2++){
                if(ok.at(p) == -1 || ok.at(p2) == -1 || swap1 != -1) continue;
                if(p+p2 == 3){
                    swap1 = ok.at(p); swap2 = ok.at(p2);
                    answer.at(ok.at(p)) = 1<<d; answer.at(ok.at(p2)) = 1<<d2;
                    idx.erase(1<<d); idx.erase(1<<d2);
                }
                else{
                    if((1<<d2)+(1<<d) > N) continue;
                    swap1 = ok.at(p); swap2 = ok.at(p2);
                    answer.at(ok.at(p)) = (1<<d)+(1<<d2); answer.at(ok.at(p2)) = 1<<d2;
                    idx.erase(answer.at(ok.at(p))); 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