結果

問題 No.153 石の山
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-18 23:52:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 534 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 11,852 KB
実行使用メモリ 10,032 KB
最終ジャッジ日時 2023-10-21 08:27:52
合計ジャッジ時間 2,306 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,032 KB
testcase_01 AC 28 ms
10,032 KB
testcase_02 AC 26 ms
10,032 KB
testcase_03 AC 26 ms
10,032 KB
testcase_04 AC 30 ms
10,032 KB
testcase_05 AC 28 ms
10,032 KB
testcase_06 AC 28 ms
10,032 KB
testcase_07 AC 27 ms
10,032 KB
testcase_08 AC 28 ms
10,032 KB
testcase_09 AC 26 ms
10,032 KB
testcase_10 AC 24 ms
10,032 KB
testcase_11 AC 25 ms
10,032 KB
testcase_12 AC 26 ms
10,032 KB
testcase_13 AC 25 ms
10,032 KB
testcase_14 AC 26 ms
10,032 KB
testcase_15 AC 27 ms
10,032 KB
testcase_16 AC 26 ms
10,032 KB
testcase_17 AC 26 ms
10,032 KB
testcase_18 AC 28 ms
10,032 KB
testcase_19 AC 25 ms
10,032 KB
testcase_20 AC 26 ms
10,032 KB
testcase_21 AC 26 ms
10,032 KB
testcase_22 AC 27 ms
10,032 KB
testcase_23 AC 26 ms
10,032 KB
testcase_24 AC 26 ms
10,032 KB
testcase_25 AC 26 ms
10,032 KB
testcase_26 AC 26 ms
10,032 KB
testcase_27 AC 26 ms
10,032 KB
testcase_28 AC 26 ms
10,032 KB
testcase_29 AC 26 ms
10,032 KB
testcase_30 AC 25 ms
10,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache


@lru_cache(maxsize=None)
def grundy(x):
    if x == 0 or x == 1:
        return 0
    if x == 2:
        return 1
    S = set()
    if x >= 2:
        a = x // 2
        b = x - a
        S.add(grundy(a) ^ grundy(b))
    if x % 3 == 1:
        S.add(grundy(x // 3 + 1))
    else:
        S.add(grundy(x // 3))
    S = sorted(S)
    for i, s in enumerate(S):
        if i == s:
            continue
        return i
    return i + 1


N = int(input())
if grundy(N):
    print("A")
else:
    print("B")
0