結果

問題 No.103 素因数ゲーム リターンズ
ユーザー Ymgch_KYmgch_K
提出日時 2017-07-10 14:39:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,536 bytes
コンパイル時間 1,839 ms
コンパイル使用メモリ 172,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:29:32
合計ジャッジ時間 2,714 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < (n); i ++)

int grundy(vector<int>& v) {
        bool f = true;
        for (int i = 0; i < v.size(); i ++) if (v[i] != 0) f = false;
        if (f) return 0;
        set<int> s;
        for (int i = 0; i < v.size(); i ++) {
                if (v[i] == 0) continue;
                v[i] --;
                s.insert(grundy(v));
                v[i] ++;
                if (v[i] < 2) continue;
                v[i] -= 2;
                s.insert(grundy(v));
                v[i] += 2;
        }
        int g = 0;
        while (s.count(g) != 0) {
                g ++;
        }
        return g;
}

int main() {
        int n;
        cin >> n;
        vector<int> m(n);
        rep(i, n) cin >> m[i];
        vector<vector<int>> ans(n);
        for (int k = 0; k < n; k ++) {
                int mm = m[k];
                for (int i = 2; i * i <= mm; i ++) {
                        if (m[k] % i) continue;
                        int cnt = 1;
                        m[k] /= i;
                        while (m[k] % i == 0) {
                                cnt ++;
                                m[k] /= i;
                        }
                        ans[k].push_back(cnt);
                }
                if (m[k] > 1) ans[k].push_back(1);
        }
        int x = grundy(ans[0]);
        for (int i = 1; i < n; i ++) {
                x ^= grundy(ans[i]);
        }
        cout << (x ? "Alice" : "Bob") << endl;
        return 0;
}

0