結果

問題 No.2732 Similar Permutations
ユーザー coindarwcoindarw
提出日時 2024-04-19 23:12:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,549 bytes
コンパイル時間 5,741 ms
コンパイル使用メモリ 338,444 KB
実行使用メモリ 17,992 KB
最終ジャッジ日時 2024-04-19 23:13:10
合計ジャッジ時間 20,451 ms
ジャッジサーバーID
(参考情報)
judge6 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 8 ms
14,916 KB
testcase_02 AC 23 ms
13,276 KB
testcase_03 AC 37 ms
15,072 KB
testcase_04 AC 15 ms
12,356 KB
testcase_05 AC 12 ms
11,964 KB
testcase_06 AC 7 ms
11,544 KB
testcase_07 AC 30 ms
14,004 KB
testcase_08 AC 16 ms
12,536 KB
testcase_09 AC 10 ms
11,880 KB
testcase_10 AC 71 ms
17,992 KB
testcase_11 AC 8 ms
11,568 KB
testcase_12 AC 62 ms
11,612 KB
testcase_13 AC 61 ms
11,584 KB
testcase_14 AC 63 ms
11,460 KB
testcase_15 AC 62 ms
11,616 KB
testcase_16 AC 45 ms
10,900 KB
testcase_17 AC 47 ms
10,920 KB
testcase_18 AC 57 ms
11,312 KB
testcase_19 AC 60 ms
11,436 KB
testcase_20 AC 60 ms
11,432 KB
testcase_21 AC 60 ms
10,940 KB
testcase_22 AC 38 ms
9,804 KB
testcase_23 AC 60 ms
10,588 KB
testcase_24 AC 36 ms
9,516 KB
testcase_25 AC 55 ms
10,340 KB
testcase_26 AC 46 ms
9,884 KB
testcase_27 AC 53 ms
10,252 KB
testcase_28 AC 43 ms
9,556 KB
testcase_29 AC 50 ms
10,092 KB
testcase_30 AC 38 ms
9,448 KB
testcase_31 AC 52 ms
10,028 KB
testcase_32 AC 46 ms
9,872 KB
testcase_33 AC 52 ms
10,184 KB
testcase_34 AC 37 ms
9,300 KB
testcase_35 AC 50 ms
10,108 KB
testcase_36 AC 47 ms
9,604 KB
testcase_37 AC 50 ms
10,044 KB
testcase_38 AC 45 ms
9,524 KB
testcase_39 AC 51 ms
9,996 KB
testcase_40 AC 43 ms
9,440 KB
testcase_41 AC 51 ms
9,788 KB
testcase_42 AC 40 ms
9,416 KB
testcase_43 AC 52 ms
9,692 KB
testcase_44 AC 29 ms
8,944 KB
testcase_45 AC 51 ms
9,696 KB
testcase_46 AC 45 ms
9,556 KB
testcase_47 AC 51 ms
9,816 KB
testcase_48 AC 32 ms
9,048 KB
testcase_49 AC 48 ms
9,648 KB
testcase_50 AC 31 ms
8,856 KB
testcase_51 AC 45 ms
8,192 KB
testcase_52 AC 42 ms
7,948 KB
testcase_53 AC 64 ms
12,768 KB
testcase_54 AC 64 ms
12,720 KB
testcase_55 AC 61 ms
12,656 KB
testcase_56 AC 66 ms
12,772 KB
testcase_57 AC 35 ms
10,876 KB
testcase_58 AC 46 ms
11,784 KB
testcase_59 AC 45 ms
11,448 KB
testcase_60 AC 37 ms
11,108 KB
testcase_61 AC 33 ms
10,752 KB
testcase_62 AC 55 ms
12,060 KB
testcase_63 AC 9 ms
15,032 KB
testcase_64 AC 9 ms
15,004 KB
testcase_65 AC 9 ms
15,056 KB
testcase_66 AC 8 ms
14,976 KB
testcase_67 AC 9 ms
15,056 KB
testcase_68 AC 11 ms
15,032 KB
testcase_69 AC 5 ms
11,072 KB
testcase_70 AC 6 ms
11,012 KB
testcase_71 AC 5 ms
11,020 KB
testcase_72 WA -
testcase_73 WA -
testcase_74 AC 5 ms
11,012 KB
testcase_75 AC 5 ms
11,024 KB
testcase_76 AC 6 ms
11,016 KB
testcase_77 AC 5 ms
11,028 KB
testcase_78 AC 5 ms
11,008 KB
testcase_79 AC 6 ms
11,100 KB
testcase_80 AC 6 ms
11,128 KB
testcase_81 AC 6 ms
11,044 KB
testcase_82 AC 5 ms
11,040 KB
testcase_83 AC 5 ms
11,032 KB
testcase_84 AC 6 ms
11,112 KB
testcase_85 AC 5 ms
11,068 KB
testcase_86 AC 5 ms
11,176 KB
testcase_87 AC 6 ms
11,044 KB
testcase_88 AC 6 ms
11,148 KB
testcase_89 AC 5 ms
11,032 KB
testcase_90 AC 6 ms
11,016 KB
testcase_91 AC 5 ms
11,076 KB
testcase_92 AC 6 ms
11,012 KB
testcase_93 AC 5 ms
11,012 KB
testcase_94 AC 7 ms
11,048 KB
testcase_95 AC 5 ms
11,028 KB
testcase_96 AC 5 ms
11,184 KB
testcase_97 AC 6 ms
11,124 KB
testcase_98 AC 6 ms
11,108 KB
testcase_99 AC 6 ms
11,100 KB
testcase_100 AC 6 ms
11,228 KB
testcase_101 AC 6 ms
11,012 KB
testcase_102 AC 5 ms
11,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>

#include <atcoder/all>
#else
#include <mylibs/all.h>
#endif

using ll = long long;
using lll = __int128_t;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define length(v) ((int)(v).size())
constexpr int inf = 2'000'000'000;
constexpr ll linf = 4'000'000'000'000'000'000, M7 = 1'000'000'007, M9 = 998'244'353;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;

// clang-format off
#define Vec(type, ...) __make_vec<type>(__VA_ARGS__)
template <class T> vector<T> __make_vec(size_t a) {return vector<T>(a);}template <class T, class... Ts>
auto __make_vec(size_t a, Ts... ts) {return vector<decltype(__make_vec<T>(ts...))>(a, __make_vec<T>(ts...));}
#define VecI(init, type, ...) __make_vecI<type, init>(__VA_ARGS__)
template <class T, T init>vector<T> __make_vecI(size_t a) {return vector<T>(a, init);}
template <class T, T init, class... Ts>
auto __make_vecI(size_t a, Ts... ts) {return vector<decltype(__make_vecI<T, init>(ts...))>(a, __make_vecI<T, init>(ts...));}

template <typename T, typename U>inline ostream& operator<<(ostream& os, const pair<T, U>& p) noexcept {return os << p.first << " " << p.second;}
inline ostream& operator<<(ostream& os, const modint& m) noexcept { return os << m.val(); }
template <int M>inline ostream& operator<<(ostream& os, const static_modint<M>& m) noexcept { return os << m.val(); }

template <typename T> struct is_static_modint : std::false_type {}; template <int MOD> struct is_static_modint<static_modint<MOD>> : std::true_type {};
template <template <typename...> typename C, typename Number>concept MyContainer = std::is_same_v<C<Number>, std::vector<Number>> || std::is_same_v<C<Number>, std::deque<Number>> || std::is_same_v<C<Number>, std::set<Number>> || std::is_same_v<C<Number>, std::unordered_set<Number>> || std::is_same_v<C<Number>, std::unordered_multiset<Number>> || std::is_same_v<C<Number>, std::multiset<Number>>;
template <typename Number>concept MyNumber = std::is_same_v<Number, int> || std::is_same_v<Number, ll> || std::is_same_v<Number, char> || std::is_same_v<Number, modint> || is_static_modint<Number>::value;
template <template <typename...> typename C, typename Number>concept MyContainerNumber = MyContainer<C, Number> && MyNumber<Number>;
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>concept MyNestedContainerNumber = MyContainer<OutCon, InCon<Number>> && MyContainerNumber<InCon, Number>;
template <template <typename...> typename C, typename Number>requires MyContainerNumber<C, Number>std::ostream& operator<<(std::ostream& os, const C<Number>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << ' ' << *itr;}return os;}
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>requires MyNestedContainerNumber<OutCon, InCon, Number>std::ostream& operator<<(std::ostream& os, const OutCon<InCon<Number>>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << '\n' << *itr;}return os;}
template <typename T, typename U>istream& operator>>(istream& is, pair<T, U>& p) {return is >> p.first >> p.second;}
template <typename T>istream& operator>>(istream& is, vector<T>& v) {for (auto& e : v) is >> e;return is;}
void inp() {}
template <typename T, typename... Args>void inp(T& a, Args&... args) {cin >> a, inp(args...);}
template <typename T>void inp1(vector<T>& v, int offset = 1, int len = -1) {if (len == -1) len = int(v.size()) - offset;assert(offset >= 0 && len >= 0);for (int i = offset; i < offset + len; ++i) cin >> v[i];}
template <typename T>void oup(const T& a) {cout << a << "\n";}
template <typename T, typename... Args>void oup(const T& a, const Args&... args) {cout << a << " ", oup(args...);}

inline string YESNO(bool cond) { return cond ? "YES" : "NO"; }inline string yesno(bool cond) { return cond ? "yes" : "no"; }inline string YesNo(bool cond) { return cond ? "Yes" : "No"; }
inline auto add1(auto vec, ll offset = 1) {for (auto& e : vec) e += offset;return vec;}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>void debug_out(T t) {cerr << t << "\n";}
template <typename T, typename... Args>void debug_out(T t, Args... args) {cerr << t << ", ";debug_out(args...);}
#endif

#ifdef ONLINE_JUDGE
#define todo(...) static_assert(false)
#else
#define todo(...)
#endif
// clang-format on

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    inp(n);
    vector<int> a(n);
    inp(a);

    int mx = *max_element(all(a));
    {
        vector<vector<int>> idx = vector<vector<int>>(mx + 1, vector<int>());
        rep(i, n) idx[a[i]].push_back(i);
        int x = -1;
        rep(i, mx + 1) {
            if (idx[i].size() >= 2) {
                x = i;
                break;
            }
        }
        debug(x);
        if (x != -1) {
            reps(i, n) cout << i << " ";
            cout << "\n";
            int c = 0;
            rep(i, n) {
                if (a[i] == x) {
                    cout << idx[x][idx[x].size() - (++c)] + 1 << " ";
                } else {
                    cout << i + 1 << " ";
                }
            }
            cout << "\n";
            return 0;
        }
    }

    {
        using P = pair<int, int>;
        vector<P> hatonosu(1e6, {-1, -1});
        int all_xor = 0;
        rep(i, n) all_xor ^= a[i] + i + 1;
        hatonosu[all_xor] = {0, 0};

        rep(i, n) rep2(j, i + 1, n) {
            int x = a[i] + i + 1;
            int y = a[j] + j + 1;
            int xx = all_xor ^ x ^ y;
            int nx = a[i] + j + 1;
            int ny = a[j] + i + 1;
            xx ^= nx ^ ny;
            if (hatonosu[xx] != P{-1, -1}) {
                vector<int> v(n);
                vector<int> ans1, ans2;
                iota(all(v), 0);
                auto [x, y] = hatonosu[xx];
                swap(v[x], v[y]);
                ans1 = v;
                iota(all(v), 0);
                swap(v[i], v[j]);
                ans2 = v;

                int x1 = 0, x2 = 0;
                rep(i, n) x1 ^= a[ans1[i]] + i + 1;
                rep(i, n) x2 ^= a[ans2[i]] + i + 1;
                if (x1 != x2) continue;
                oup(add1(ans1));
                oup(add1(ans2));
                return 0;
            }
            hatonosu[xx] = {i, j};
        }
    }

    vector<vector<int>> hatonosu = vector<vector<int>>(5e5, vector<int>());
    int m = min(n, 10);
    vector<int> ans(m);
    iota(all(ans), 0);
    do {
        int ax = 0;
        rep(i, m) ax ^= a[ans[i]] + i + 1;
        if (hatonosu.at(ax).empty()) {
            hatonosu.at(ax) = ans;
        } else {
            auto ans2 = hatonosu.at(ax);
            rep2(i, m, n) {
                ans.push_back(i);
                ans2.push_back(i);
            }
            oup(add1(ans));
            oup(add1(ans2));
            return 0;
        }
    } while (next_permutation(all(ans)));
    oup(-1);
    return 0;
}
0