結果

問題 No.153 石の山
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-31 00:52:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 69 ms / 5,000 ms
コード長 750 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 86,800 KB
実行使用メモリ 71,388 KB
最終ジャッジ日時 2023-08-20 20:44:46
合計ジャッジ時間 3,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,156 KB
testcase_01 AC 60 ms
71,112 KB
testcase_02 AC 60 ms
71,184 KB
testcase_03 AC 62 ms
71,240 KB
testcase_04 AC 63 ms
71,036 KB
testcase_05 AC 68 ms
71,124 KB
testcase_06 AC 64 ms
71,008 KB
testcase_07 AC 62 ms
71,036 KB
testcase_08 AC 61 ms
71,060 KB
testcase_09 AC 65 ms
71,116 KB
testcase_10 AC 60 ms
71,132 KB
testcase_11 AC 62 ms
71,116 KB
testcase_12 AC 66 ms
70,884 KB
testcase_13 AC 68 ms
71,024 KB
testcase_14 AC 63 ms
71,236 KB
testcase_15 AC 62 ms
71,112 KB
testcase_16 AC 63 ms
71,036 KB
testcase_17 AC 62 ms
71,364 KB
testcase_18 AC 62 ms
71,068 KB
testcase_19 AC 60 ms
71,092 KB
testcase_20 AC 69 ms
71,196 KB
testcase_21 AC 64 ms
71,388 KB
testcase_22 AC 62 ms
71,084 KB
testcase_23 AC 61 ms
71,008 KB
testcase_24 AC 62 ms
71,116 KB
testcase_25 AC 62 ms
71,120 KB
testcase_26 AC 61 ms
71,244 KB
testcase_27 AC 62 ms
71,112 KB
testcase_28 AC 66 ms
71,144 KB
testcase_29 AC 62 ms
71,356 KB
testcase_30 AC 60 ms
71,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
if n == 1:
    print('B')
    exit()
grundy = [-1]*(n+1)
grundy[0] = 0
grundy[1] = 0
for i in range(2, n+1):
    S = set()
    if i%2 == 0:
        g = grundy[i//2]^grundy[i//2]
        S.add(g)
    else:
        g = grundy[(i-1)//2]^grundy[(i-1)//2+1]
        S.add(g)
    if i%3 == 0:
        g = grundy[i//3]^grundy[i//3]^grundy[i//3]
        S.add(g)
    elif i%3 == 1:
        g = grundy[(i-1)//3]^grundy[(i-1)//3]^grundy[(i-1)//3+1]
        S.add(g)
    else:
        g = grundy[(i-1)//3]^grundy[(i-1)//3+1]^grundy[(i-1)//3+1]
        S.add(g)
    g = 0
    while True:
        if g not in S:
            break
        else:
            g += 1
    grundy[i] = g
#print(grundy)
if grundy[n]:
    print('A')
else:
    print('B')
0