結果

問題 No.103 素因数ゲーム リターンズ
ユーザー warashiwarashi
提出日時 2015-02-10 15:33:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,788 ms / 5,000 ms
コード長 1,018 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 16,716 KB
最終ジャッジ日時 2023-09-05 22:47:29
合計ジャッジ時間 7,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,588 KB
testcase_01 AC 19 ms
8,524 KB
testcase_02 AC 19 ms
8,532 KB
testcase_03 AC 19 ms
8,548 KB
testcase_04 AC 19 ms
8,536 KB
testcase_05 AC 19 ms
8,532 KB
testcase_06 AC 20 ms
8,548 KB
testcase_07 AC 18 ms
8,712 KB
testcase_08 AC 19 ms
8,572 KB
testcase_09 AC 20 ms
8,572 KB
testcase_10 AC 20 ms
8,532 KB
testcase_11 AC 22 ms
8,540 KB
testcase_12 AC 217 ms
9,848 KB
testcase_13 AC 230 ms
9,812 KB
testcase_14 AC 573 ms
10,836 KB
testcase_15 AC 489 ms
10,716 KB
testcase_16 AC 23 ms
8,568 KB
testcase_17 AC 928 ms
12,208 KB
testcase_18 AC 44 ms
8,756 KB
testcase_19 AC 2,788 ms
16,716 KB
testcase_20 AC 55 ms
8,996 KB
testcase_21 AC 193 ms
9,780 KB
testcase_22 AC 55 ms
8,860 KB
testcase_23 AC 90 ms
9,216 KB
testcase_24 AC 101 ms
9,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import time
from collections import defaultdict


def memoize(fn):
    table = {}

    def func(*args):
        if args not in table:
            table[args] = fn(*args)
        return table[args]
    return func


def prime_factorization(n):
    factor = defaultdict(int)
    i = 2
    while i * i <= n:
        while n % i == 0:
            n = n // i
            factor[i] += 1
        i += 1
    if n > 1:
        factor[n] += 1
    return factor


@memoize
def nim(nums):
    if sum(nums) == 0:
        True
    for i in range(len(nums)):
        for j in (1, 2):
            if nums[i] < j:
                continue
            tmp = list(nums)
            tmp[i] -= j
            if nim(tuple(sorted(tmp))):
                return False
    return True

N = int(input())
M = [int(x) for x in input().split()]
init = []
for m in M:
    init.extend(sorted(prime_factorization(m).values()))
init = [x % 3 for x in init]
if nim(tuple(sorted(init))):
    print("Bob")
else:
    print("Alice")
0