結果

問題 No.103 素因数ゲーム リターンズ
ユーザー warashiwarashi
提出日時 2015-02-10 11:37:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,069 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 9,004 KB
最終ジャッジ日時 2023-09-05 21:38:23
合計ジャッジ時間 7,105 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,704 KB
testcase_01 AC 20 ms
8,704 KB
testcase_02 AC 20 ms
8,648 KB
testcase_03 AC 29 ms
9,004 KB
testcase_04 AC 21 ms
8,664 KB
testcase_05 AC 20 ms
8,712 KB
testcase_06 AC 20 ms
8,672 KB
testcase_07 AC 20 ms
8,668 KB
testcase_08 AC 20 ms
8,660 KB
testcase_09 AC 19 ms
8,724 KB
testcase_10 AC 20 ms
8,836 KB
testcase_11 AC 25 ms
8,864 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


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


def Bob_win(nums):
    if len(list(filter(lambda x: x > 1, nums))) > 0:
        return False
    if nums.count(1) % 2 == 0:
        return True
    return False


@functools.lru_cache(maxsize=None)
def nim(nums):
    if Bob_win(nums) == 0:
        True
    for i in range(len(nums)):
        for j in (1, 2):
            if j > nums[i]:
                continue
            tmp = list(nums)
            tmp[i] -= j
            if nim(tuple(sorted(tmp))):
                return False
    return True

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