結果

問題 No.2732 Similar Permutations
ユーザー otoshigootoshigo
提出日時 2024-04-19 22:15:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 2,356 bytes
コンパイル時間 2,466 ms
コンパイル使用メモリ 208,948 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-19 22:15:39
合計ジャッジ時間 16,281 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 17 ms
5,376 KB
testcase_03 AC 29 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 24 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 49 ms
6,400 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 51 ms
6,528 KB
testcase_13 AC 48 ms
6,528 KB
testcase_14 AC 49 ms
6,528 KB
testcase_15 AC 49 ms
6,656 KB
testcase_16 AC 38 ms
5,632 KB
testcase_17 AC 34 ms
5,760 KB
testcase_18 AC 46 ms
6,144 KB
testcase_19 AC 52 ms
6,528 KB
testcase_20 AC 52 ms
6,528 KB
testcase_21 AC 50 ms
6,528 KB
testcase_22 AC 30 ms
5,376 KB
testcase_23 AC 51 ms
6,528 KB
testcase_24 AC 32 ms
5,376 KB
testcase_25 AC 52 ms
6,528 KB
testcase_26 AC 42 ms
6,016 KB
testcase_27 AC 51 ms
6,528 KB
testcase_28 AC 39 ms
5,760 KB
testcase_29 AC 49 ms
6,528 KB
testcase_30 AC 35 ms
5,632 KB
testcase_31 AC 48 ms
6,528 KB
testcase_32 AC 46 ms
6,400 KB
testcase_33 AC 51 ms
6,656 KB
testcase_34 AC 36 ms
5,376 KB
testcase_35 AC 51 ms
6,528 KB
testcase_36 AC 48 ms
6,144 KB
testcase_37 AC 50 ms
6,400 KB
testcase_38 AC 44 ms
6,144 KB
testcase_39 AC 50 ms
6,528 KB
testcase_40 AC 39 ms
6,016 KB
testcase_41 AC 48 ms
6,528 KB
testcase_42 AC 37 ms
5,760 KB
testcase_43 AC 49 ms
6,656 KB
testcase_44 AC 26 ms
5,376 KB
testcase_45 AC 49 ms
6,528 KB
testcase_46 AC 45 ms
6,016 KB
testcase_47 AC 48 ms
6,528 KB
testcase_48 AC 31 ms
5,376 KB
testcase_49 AC 50 ms
6,528 KB
testcase_50 AC 30 ms
5,376 KB
testcase_51 AC 45 ms
6,528 KB
testcase_52 AC 40 ms
6,016 KB
testcase_53 AC 49 ms
6,528 KB
testcase_54 AC 51 ms
6,528 KB
testcase_55 AC 50 ms
6,528 KB
testcase_56 AC 49 ms
6,528 KB
testcase_57 AC 27 ms
5,376 KB
testcase_58 AC 34 ms
5,632 KB
testcase_59 AC 35 ms
5,504 KB
testcase_60 AC 29 ms
5,376 KB
testcase_61 AC 26 ms
5,376 KB
testcase_62 AC 41 ms
6,016 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 2 ms
5,376 KB
testcase_68 AC 1 ms
5,376 KB
testcase_69 AC 1 ms
5,376 KB
testcase_70 AC 2 ms
5,376 KB
testcase_71 AC 1 ms
5,376 KB
testcase_72 AC 2 ms
5,376 KB
testcase_73 AC 2 ms
5,376 KB
testcase_74 AC 1 ms
5,376 KB
testcase_75 AC 2 ms
5,376 KB
testcase_76 AC 1 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 AC 1 ms
5,376 KB
testcase_82 AC 1 ms
5,376 KB
testcase_83 AC 2 ms
5,376 KB
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 1 ms
5,376 KB
testcase_90 AC 1 ms
5,376 KB
testcase_91 AC 2 ms
5,376 KB
testcase_92 AC 2 ms
5,376 KB
testcase_93 AC 2 ms
5,376 KB
testcase_94 AC 2 ms
5,376 KB
testcase_95 AC 2 ms
5,376 KB
testcase_96 AC 2 ms
5,376 KB
testcase_97 AC 1 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;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand(time(NULL));
    int N;
    cin>>N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    vector<int>P(N);
    for(int i=0;i<N;i++)P[i]=i+1;
    if(N<=10){
        map<int,vector<int>>mp;
        do{
            int xr=0;
            for(int i=0;i<N;i++)xr^=P[i]+A[i];
            if(mp.count(xr)){
                for(int i=0;i<N;i++){
                    cout<<mp[xr][i]<<" ";
                }
                cout<<"\n";
                for(int i=0;i<N;i++){
                    cout<<P[i]<<" ";
                }
                cout<<"\n";
                return 0;
            }
            mp[xr]=P;
        }while(next_permutation(all(P)));
        cout<<-1<<"\n";
        return 0;
    }
    map<int,vector<int>>mp;
    int xr=0;
    for(int i=0;i<N;i++)xr^=P[i]+A[i];
    mp[xr]={};
    for(int q=1;;q++){
        int r=rand()%10+2;
        vector<int>v;
        v.push_back(rand()%(N-r+1));
        for(int i=1;i<r;i++){
            v.push_back(v.back()+rand()%(N-(r-i)-v.back())+1);
        }
        int xr2=xr;
        for(int i=0;i<r;i++){
            xr2^=P[v[i]]+A[v[i]];
            xr2^=P[v[(i+1)%r]]+A[v[i]];
        }
        if(mp.count(xr2)){
            if(mp[xr2]!=v){
                vector<int>P1(N),P2(N);
                for(int i=0;i<N;i++){
                    P1[i]=i+1;
                    P2[i]=i+1;
                }
                for(int i=0;i<mp[xr2].size();i++){
                    P1[mp[xr2][i]]=mp[xr2][(i+1)%(int)mp[xr2].size()]+1;
                }
                for(int i=0;i<r;i++){
                    P2[v[i]]=v[(i+1)%r]+1;
                }
                for(int i=0;i<N;i++)cout<<P1[i]<<" ";
                cout<<"\n";
                for(int i=0;i<N;i++)cout<<P2[i]<<" ";
                cout<<"\n";
                return 0;
            }
        }else{
            mp[xr2]=v;
        }
    }
}
0