結果

問題 No.2732 Similar Permutations
ユーザー t98slider
提出日時 2024-05-05 11:27:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 200,324 KB
最終ジャッジ日時 2025-02-21 11:01:08
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 101
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int c = min(n, 9);
    vector<int> a(n), p(c);
    for(auto &&v : a) cin >> v;
    iota(p.begin(), p.end(), 1);
    vector<vector<int>> tb(2 << __lg(200010));
    do{
        int v = 0;
        for(int i = 0; i < c; i++){
            v ^= a[i] + p[i];
        }
        if(!tb[v].empty()){
            for(int i = 0; i < n; i++){
                cout << (i < c ? tb[v][i] : i + 1) << (i + 1 == n ? '\n' : ' ');
            }
            for(int i = 0; i < n; i++){
                cout << (i < c ? p[i] : i + 1) << (i + 1 == n ? '\n' : ' ');
            }
            return 0;
        }
        tb[v] = p;
    }while(next_permutation(p.begin(), p.end()));
    cout << -1 << '\n';
}
0