結果
問題 |
No.153 石の山
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:48:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 40 ms / 5,000 ms |
コード長 | 1,581 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 53,980 KB |
最終ジャッジ日時 | 2025-03-20 18:50:11 |
合計ジャッジ時間 | 2,652 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 27 |
ソースコード
def determine_winner(): max_n = 100 grundy = [0] * (max_n + 1) grundy[1] = 0 # 1 stones cannot split, lose immediately for n in range(2, max_n + 1): moves = set() # Check 2-split possibilities if n % 2 == 0: x = n // 2 if x >= 1: # Split into two parts x, x g = grundy[x] ^ grundy[x] moves.add(g) else: x = (n - 1) // 2 if x >= 1: # Split into x and x+1 g = grundy[x] ^ grundy[x + 1] moves.add(g) # Check 3-split possibilities if n >= 3: # Case 3x if n % 3 == 0: x = n // 3 if x >= 1: g = grundy[x] ^ grundy[x] ^ grundy[x] moves.add(g) # Case 3x + 1 if (n - 1) % 3 == 0: x = (n - 1) // 3 if x >= 1: g = grundy[x] ^ grundy[x] ^ grundy[x + 1] moves.add(g) # Case 3x + 2 if (n - 2) % 3 == 0: x = (n - 2) // 3 if x >= 1: g = grundy[x] ^ grundy[x + 1] ^ grundy[x + 1] moves.add(g) # Calculate mex for current n mex = 0 while True: if mex not in moves: grundy[n] = mex break mex += 1 n = int(input()) return 'A' if grundy[n] != 0 else 'B' print(determine_winner())