結果

問題 No.103 素因数ゲーム リターンズ
ユーザー xuzijian629xuzijian629
提出日時 2018-11-07 00:50:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,309 bytes
コンパイル時間 2,853 ms
コンパイル使用メモリ 207,088 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 03:56:54
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

vi ds[10001];
vi g;

int grundy(int k) {
    if (g[k] != -1) return g[k];
    vi tmp;
    for (int d: ds[k]) {
        if (k % (d * d) == 0) {
            tmp.push_back(grundy(k / d / d));
        }
        tmp.push_back(grundy(k / d));
    }
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] != i) {
            g[k] = i;
            return g[k];
        }
    }
    g[k] = tmp.size();
    return g[k];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (int i = 2; i < 10001; i++) {
        int k = i;
        while (k > 1) {
            for (int j = 2; j <= k; j++) {
                if (k % j == 0) {
                    ds[i].push_back(j);
                    while (k % j == 0) {
                        k /= j;
                    }
                    break;
                }
            }
        }
    }

    g.assign(10001, -1);
    g[1] = 0;

    int x = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        x ^= grundy(m);
    }

    cout << (x ? "Alice" : "Bob") << endl;
}
0