結果

問題 No.1881 Everything is the same...
ユーザー hitonanodehitonanode
提出日時 2022-03-18 22:35:40
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 9,413 bytes
コンパイル時間 3,201 ms
コンパイル使用メモリ 216,268 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-03 07:28:35
合計ジャッジ時間 6,924 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 1 ms
6,820 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 2 ms
6,816 KB
testcase_04 AC 1 ms
6,816 KB
testcase_05 AC 2 ms
6,820 KB
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 1 ms
6,820 KB
testcase_08 AC 1 ms
6,820 KB
testcase_09 AC 2 ms
6,816 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 2 ms
6,816 KB
testcase_43 AC 2 ms
6,816 KB
testcase_44 AC 2 ms
6,820 KB
testcase_45 AC 2 ms
6,816 KB
testcase_46 AC 2 ms
6,816 KB
testcase_47 AC 2 ms
6,820 KB
testcase_48 AC 1 ms
6,816 KB
testcase_49 AC 2 ms
6,816 KB
testcase_50 AC 1 ms
6,820 KB
testcase_51 AC 2 ms
6,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template <typename T, typename V>
void ndarray(vector<T>& vec, const V& val, int len) { vec.assign(len, val); }
template <typename T, typename V, typename... Args> void ndarray(vector<T>& vec, const V& val, int len, Args... args) { vec.resize(len), for_each(begin(vec), end(vec), [&](T& v) { ndarray(v, val, args...); }); }
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }
int floor_lg(long long x) { return x <= 0 ? -1 : 63 - __builtin_clzll(x); }
template <typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template <typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
template <typename T> vector<T> sort_unique(vector<T> vec) { sort(vec.begin(), vec.end()), vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; }
template <typename T> int arglb(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::lower_bound(v.begin(), v.end(), x)); }
template <typename T> int argub(const std::vector<T> &v, const T &x) { return std::distance(v.begin(), std::upper_bound(v.begin(), v.end(), x)); }
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << '['; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T, size_t sz> ostream &operator<<(ostream &os, const array<T, sz> &arr) { os << '['; for (auto v : arr) os << v << ','; os << ']'; return os; }
#if __cplusplus >= 201703L
template <typename... T> istream &operator>>(istream &is, tuple<T...> &tpl) { std::apply([&is](auto &&... args) { ((is >> args), ...);}, tpl); return is; }
template <typename... T> ostream &operator<<(ostream &os, const tuple<T...> &tpl) { os << '('; std::apply([&os](auto &&... args) { ((os << args << ','), ...);}, tpl); return os << ')'; }
#endif
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T, typename TH> ostream &operator<<(ostream &os, const unordered_set<T, TH> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; }
template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
template <typename TK, typename TV, typename TH> ostream &operator<<(ostream &os, const unordered_map<TK, TV, TH> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; }
#ifdef HITONANODE_LOCAL
const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[1;31m", BRIGHT_CYAN = "\033[1;36m", NORMAL_CROSSED = "\033[0;9;37m", RED_BACKGROUND = "\033[1;41m", NORMAL_FAINT = "\033[0;2m";
#define dbg(x) cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl
#define dbgif(cond, x) ((cond) ? cerr << BRIGHT_CYAN << #x << COLOR_RESET << " = " << (x) << NORMAL_FAINT << " (L" << __LINE__ << ") " << __FILE__ << COLOR_RESET << endl : cerr)
#else
#define dbg(x) (x)
#define dbgif(cond, x) 0
#endif

// UnionFind Tree (0-indexed), based on size of each disjoint set
struct UnionFind {
    std::vector<int> par, cou;
    UnionFind(int N = 0) : par(N), cou(N, 1) { iota(par.begin(), par.end(), 0); }
    int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (cou[x] < cou[y]) std::swap(x, y);
        par[y] = x, cou[x] += cou[y];
        return true;
    }
    int count(int x) { return cou[find(x)]; }
    bool same(int x, int y) { return find(x) == find(y); }

    vector<int> hash() {
        map<int, vector<int>> mp;
        REP(i, par.size()) mp[find(i)].push_back(i);

        vector<int> ret(par.size(), -1);
        for (auto [r, vs] : mp) {
            int lo = par.size();
            for (auto x : vs) chmin(lo, x);
            for (auto x : vs) ret[x] = lo;
        }
        return ret;
    }
};

struct rand_int_ {
    using lint = long long;
    mt19937 mt;
    rand_int_() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    lint operator()(lint x) { return this->operator()(0, x); } // [0, x)
    lint operator()(lint l, lint r) {
        uniform_int_distribution<lint> d(l, r - 1);
        return d(mt);
    }
} rnd;

int exp2(int N) {
    vector<vector<int>> states;
    UnionFind uf(N);
    set<vector<int>> visited;
    states.push_back(uf.hash());
    visited.insert(uf.hash());

    int cur = 0;
    while (cur < int(states.size())) {
        const auto hash = states[cur];
        // dbg(hash);

        FOR(i, 1, N) {
            if (__gcd(i, N) != 1) continue;

            UnionFind current(N);
            current.par = hash;
            REP(x, N) current.unite(x, i * x % N);
            auto ch = current.hash();
            if (ch != hash and !visited.count(ch)) {
                visited.insert(ch);
                states.push_back(ch);
            }
        }

        cur++;
    }
    states = sort_unique(states);
    // dbg(states);

    vector<vector<int>> to(states.size());
    REP(now, states.size()) {
        FOR(i, 1, N) {
            if (__gcd(i, N) != 1) continue;
            UnionFind current(N);
            current.par = states[now];
            REP(x, N) current.unite(x, i * x % N);
            int nxt = arglb(states, current.hash());
            if (now != nxt) to[now].push_back(nxt);
        }
    }

    vector<int> grundy(states.size(), -1);
    int start = arglb(states, UnionFind(N).hash());
    auto rec = [&](auto &&self, int now) -> void {
        vector<int> em;
        for (auto nxt : to[now]) {
            if (grundy[nxt] < 0) self(self, nxt);
            em.push_back(grundy[nxt]);
        }
        em = sort_unique(em);
        int cur = 0;
        while (cur < int(em.size()) and em[cur] == cur) ++cur;
        grundy[now] = cur;
    };
    rec(rec, start);
    dbg(make_pair(N, grundy.at(start)));
    return grundy.at(start);
}

void experiment() {
    REP(t, 1000) {
        int N = rnd(5, 1001);
        UnionFind uf(N);

        vector<int> gs{N};
        REP(t, 1000) {
            int g = 0;
            while (__gcd(g, N) != 1) {
                g = rnd(1, N);
            }
            bool join = false;
            REP(i, N) join |= uf.unite(i, i * g % N);
            if (join) gs.push_back(g);
            if (uf.count(0) == N) break;
        }
        vector<int> roots;
        REP(i, N) roots.push_back(uf.find(i));
        gs.push_back(sort_unique(roots).size());
        dbg(gs);
    }
}


int main() {
    // vector<int> tmp;
    // FOR(n, 1, 200) tmp.push_back(exp2(n));
    // dbg(tmp);

    vector<int> grundy{0,0,1,1,2,1,2,0,2,2,2,0,3,2,3,3,4,2,3,3,3,2,2,1,3,3,3,3,3,3,3,4,3,4,4,3,4,3,4,2,4,3,3,3,4,2,2,2,3,3,5,4,3,3,4,2,4,3,2,2,4,3,0,5,1,3,3,5,3,4,3,2,5,4,4,4,4,4,3,1,4,4,2,2,6,3,4,2,4,4,1,3,4,2,5,5,6,3,4,4,4,5,3,5,5,3,2,4,5,4,5,5,5,4,4,4,1,2,6,3,3,4,5,4,4,0,4,6,4,1,3,2,1,3,5,6,4,3,3,5,3,3,5,5,1,5,4,5,3,4,4,5,6,4,5,5,4,3,4,6,4,4,5,5,5,2,2,3,4,6,1,4,3,4,5,5,3,4,2,5,5,1,5,2,6,4,6,3,1,5,3,6,7,6,6,4,4,4,4};

    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;
    int ax = 0;
    for (auto a : A) ax ^= grundy.at(a - 1);
    cout << (ax ? "Y" : "X") << '\n';
}
0