結果

問題 No.2732 Similar Permutations
ユーザー 👑 nu50218nu50218
提出日時 2024-04-19 23:13:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,330 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 198,252 KB
実行使用メモリ 7,672 KB
最終ジャッジ日時 2024-04-19 23:14:25
合計ジャッジ時間 42,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 75 ms
5,376 KB
testcase_03 AC 136 ms
5,376 KB
testcase_04 AC 108 ms
5,376 KB
testcase_05 AC 44 ms
5,376 KB
testcase_06 AC 15 ms
5,376 KB
testcase_07 AC 465 ms
5,560 KB
testcase_08 AC 92 ms
5,376 KB
testcase_09 AC 27 ms
5,376 KB
testcase_10 AC 1,252 ms
7,396 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 485 ms
6,648 KB
testcase_13 AC 1,716 ms
7,672 KB
testcase_14 AC 824 ms
6,652 KB
testcase_15 AC 951 ms
6,940 KB
testcase_16 AC 826 ms
6,428 KB
testcase_17 AC 72 ms
5,520 KB
testcase_18 AC 285 ms
6,072 KB
testcase_19 AC 1,554 ms
7,540 KB
testcase_20 AC 949 ms
6,892 KB
testcase_21 AC 392 ms
6,136 KB
testcase_22 AC 437 ms
6,048 KB
testcase_23 AC 492 ms
6,260 KB
testcase_24 AC 370 ms
5,680 KB
testcase_25 AC 369 ms
6,132 KB
testcase_26 AC 187 ms
6,128 KB
testcase_27 AC 296 ms
6,132 KB
testcase_28 AC 368 ms
5,708 KB
testcase_29 AC 111 ms
6,132 KB
testcase_30 AC 214 ms
5,376 KB
testcase_31 AC 138 ms
5,880 KB
testcase_32 AC 96 ms
5,436 KB
testcase_33 AC 117 ms
5,632 KB
testcase_34 AC 94 ms
5,376 KB
testcase_35 AC 191 ms
5,880 KB
testcase_36 AC 100 ms
5,440 KB
testcase_37 AC 90 ms
5,880 KB
testcase_38 AC 78 ms
5,392 KB
testcase_39 AC 97 ms
5,624 KB
testcase_40 AC 60 ms
5,400 KB
testcase_41 AC 66 ms
5,712 KB
testcase_42 AC 45 ms
5,376 KB
testcase_43 AC 66 ms
5,756 KB
testcase_44 AC 32 ms
5,376 KB
testcase_45 AC 66 ms
5,624 KB
testcase_46 AC 60 ms
5,420 KB
testcase_47 AC 64 ms
5,628 KB
testcase_48 AC 33 ms
5,376 KB
testcase_49 AC 58 ms
5,624 KB
testcase_50 AC 36 ms
5,376 KB
testcase_51 AC 58 ms
5,756 KB
testcase_52 AC 50 ms
5,376 KB
testcase_53 AC 1,008 ms
6,904 KB
testcase_54 AC 704 ms
6,648 KB
testcase_55 AC 864 ms
6,904 KB
testcase_56 AC 1,435 ms
7,548 KB
testcase_57 AC 440 ms
5,628 KB
testcase_58 AC 1,130 ms
7,052 KB
testcase_59 AC 655 ms
6,132 KB
testcase_60 AC 589 ms
6,048 KB
testcase_61 AC 521 ms
5,892 KB
testcase_62 AC 892 ms
6,944 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 AC 2 ms
5,376 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 AC 2 ms
5,376 KB
testcase_74 WA -
testcase_75 AC 2 ms
5,376 KB
testcase_76 WA -
testcase_77 AC 2 ms
5,376 KB
testcase_78 WA -
testcase_79 AC 1 ms
5,376 KB
testcase_80 AC 1 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 1 ms
5,376 KB
testcase_87 AC 1 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 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 3 ms
5,376 KB
testcase_97 AC 2 ms
5,376 KB
testcase_98 AC 1 ms
5,376 KB
testcase_99 AC 3 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 #

#line 1 "main.cpp"
#ifdef LOCAL
#include <local.hpp>
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define postprocess(...) ((void)0)
#endif

#line 2 "library/misc/xorshift.hpp"

#include <bits/stdc++.h>

inline uint32_t xorshift32() {
    static uint32_t x = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    x ^= x << 13;
    x ^= x >> 17;
    x ^= x << 5;
    return x;
}

inline uint64_t xorshift64() {
    static uint64_t x = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    x ^= x << 13;
    x ^= x >> 7;
    x ^= x << 17;
    return x;
}
#line 10 "main.cpp"

using namespace std;
using ll = long long;
using ld = long double;

struct RNG {
    void setSeed(uint64_t seed) {
        seedSet = true;
        x = seed;
    }

    template <class T>
    T choice(std::vector<T>& v) {
        assert(!v.empty());
        return v[range(0, (int)v.size() - 1)];
    }

    template <class T>
    void shuffle(std::vector<T>& v) {
        const int N = v.size();
        for (int i = 0; i < N - 1; i++) {
            const int j = range(i, N - 1);
            if (i == j) continue;
            std::swap(v[i], v[j]);
        }
    }

    // generate random integers in [from, to]
    template <class T, class U>
    typename std::common_type<T, U>::type range(T from, U to) {
        static_assert(std::is_integral_v<T>);
        static_assert(std::is_integral_v<U>);
        static_assert(std::is_integral_v<typename std::common_type<T, U>::type>);

        assert(from <= to);

        uint64_t width = to - from + 1;

        typename std::common_type<T, U>::type ret = from;
        ret += xorshift64() % width;

        return ret;
    }

   private:
    bool seedSet = false;
    uint64_t x;

    uint64_t xorshift64() {
        assert(seedSet);
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        return x;
    }
} rng;

vector<int> random_permutation(const int N, const uint64_t seed) {
    rng.setSeed(seed);
    vector<int> ret(N);
    iota(ret.begin(), ret.end(), 1);
    rng.shuffle(ret);
    return ret;
}

uint64_t memo[1000000];

void solve([[maybe_unused]] int test) {
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto&& x : A) {
        cin >> x;
    }

    auto start = chrono::high_resolution_clock::now();
    while (true) {
        auto now = chrono::high_resolution_clock::now();
        auto ms = chrono::duration_cast<chrono::milliseconds>(now - start).count();
        if (ms > 1950) break;

        const uint64_t seed = max(1ul, xorshift64());
        const auto P = random_permutation(N, seed);

        int xorsum = 0;
        for (int i = 0; i < N; i++) {
            xorsum ^= (P[i] + A[i]);
        }
        if (memo[xorsum] > 0) {
            const auto P2 = random_permutation(N, memo[xorsum]);
            for (int i = 0; i < N; i++) {
                cout << P[i] << (i == N - 1 ? "\n" : " ");
            }
            for (int i = 0; i < N; i++) {
                cout << P2[i] << (i == N - 1 ? "\n" : " ");
            }
            return;
        }
        memo[xorsum] = seed;
    }

    cout << -1 << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++) {
        solve(i);
    }

    postprocess();
}
0