結果
問題 |
No.3112 Decrement or Mod Game
|
ユーザー |
|
提出日時 | 2025-04-18 22:39:12 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 861 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 11,776 KB |
実行使用メモリ | 487,900 KB |
最終ジャッジ日時 | 2025-04-18 22:39:29 |
合計ジャッジ時間 | 7,279 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 5 -- * 60 |
ソースコード
import sys sys.setrecursionlimit(10**7) from functools import lru_cache @lru_cache(None) def win(a: int, b: int) -> bool: # normalize so that a >= b if a < b: return not win(b, a) # if you can do a % b == 0, you win instantly if a % b == 0: return True # 1) try the mod move r = a % b if not win(b, r): return True # 2) try the decrement move (a → a-1) # opponent then faces (b, a-1) # we win if that position is losing if a - 1 < b: # will swap inside win() if not win(a - 1, b): return True else: if not win(b, a - 1): return True # no winning move return False def main(): data = sys.stdin.read().split() A, B = map(int, data) print("Alice" if win(A, B) else "Bob") if __name__ == "__main__": main()