結果

問題 No.2732 Similar Permutations
ユーザー eve__fuyuki
提出日時 2024-04-19 22:20:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,010 bytes
コンパイル時間 2,918 ms
コンパイル使用メモリ 205,008 KB
最終ジャッジ日時 2025-02-21 04:32:57
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 90 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (n == 1) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    if (n <= 9) {
        map<int, vector<int>> mp;
        do {
            int x = 0;
            for (int i = 0; i < n; i++) {
                x ^= a[i] + p[i];
            }
            if (mp.find(x) == mp.end()) {
                mp[x] = p;
            } else {
                auto pp = mp[x];
                for (int i = 0; i < n; i++) {
                    cout << pp[i] << " ";
                }
                cout << "\n";
                for (int i = 0; i < n; i++) {
                    cout << p[i] << " ";
                }
                cout << "\n";
                return 0;
            }
        } while (next_permutation(p.begin(), p.end()));
        cout << -1 << endl;
        return 0;
    }
    int s9 = 0;
    for (int i = 10; i <= n; i++) {
        s9 ^= a[i - 1] + i;
    }
    vector<int> p9(9);
    iota(p9.begin(), p9.end(), 1);
    map<int, vector<int>> mp;

    do {
        int x = s9;
        for (int i = 0; i < 9; i++) {
            x ^= a[i] + p9[i];
        }
        if (mp.find(x) == mp.end()) {
            mp[x] = p;
        } else {
            auto pp = mp[x];
            for (int i = 0; i < 9; i++) {
                cout << pp[i] << " ";
            }
            for (int i = 10; i <= n; i++) {
                cout << i << " ";
            }
            cout << "\n";
            for (int i = 0; i < 9; i++) {
                cout << p9[i] << " ";
            }
            for (int i = 10; i <= n; i++) {
                cout << i << " ";
            }
            cout << "\n";
            return 0;
        }
    } while (next_permutation(p9.begin(), p9.end()));
}
0