結果

問題 No.103 素因数ゲーム リターンズ
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-05-13 18:34:12
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-15 16:27:05
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,880 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 35 ms
11,008 KB
testcase_03 AC 47 ms
10,880 KB
testcase_04 AC 35 ms
10,752 KB
testcase_05 AC 35 ms
10,752 KB
testcase_06 AC 33 ms
10,880 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 32 ms
11,008 KB
testcase_10 AC 32 ms
11,008 KB
testcase_11 AC 77 ms
11,648 KB
testcase_12 AC 80 ms
12,032 KB
testcase_13 AC 79 ms
11,776 KB
testcase_14 AC 80 ms
11,648 KB
testcase_15 AC 81 ms
12,032 KB
testcase_16 AC 78 ms
11,904 KB
testcase_17 AC 80 ms
11,904 KB
testcase_18 AC 79 ms
11,776 KB
testcase_19 AC 79 ms
12,032 KB
testcase_20 AC 73 ms
11,904 KB
testcase_21 AC 76 ms
11,648 KB
testcase_22 AC 79 ms
11,776 KB
testcase_23 AC 78 ms
11,904 KB
testcase_24 AC 80 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import array
import functools
import operator


def mex(s):
    m = 0
    for x in sorted(s):
        if x == m:
            m += 1
        else:
            break
    return m


def distinct_factors(n, typecode="I"):
    fs = array.array(typecode)
    for i in range(2, n):
        if i * i > n:
            break
        elif n % i == 0:
            fs.append(i)
            while n % i == 0:
                n //= i
    if n > 1:
        fs.append(n)
    return fs


def can_alice_win(ms):
    max_m = max(ms)
    factors_table = list(map(distinct_factors, range(0, max_m + 1)))
    gs = array.array("I", (0 for _ in range(max_m + 1)))
    for i in range(2, max_m + 1):
        next_gs = set()
        for f in factors_table[i]:
            next_gs.add(gs[i // f])
            if i % (f * f) == 0:
                next_gs.add(gs[i // f // f])
        gs[i] = mex(next_gs)
    return functools.reduce(operator.xor, (gs[m] for m in ms)) > 0


def main():
    _ = input()
    ms = array.array("I", map(int, input().split()))
    print("Alice" if can_alice_win(ms) else "Bob")


if __name__ == '__main__':
    main()
0