結果

問題 No.3112 Decrement or Mod Game
コンテスト
ユーザー Kevgen
提出日時 2025-04-18 22:36:47
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
MLE  
実行時間 -
コード長 874 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 278 ms
コンパイル使用メモリ 21,412 KB
実行使用メモリ 538,384 KB
最終ジャッジ日時 2026-07-09 19:31:51
合計ジャッジ時間 7,248 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 1 -- * 64
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(10**7)
from functools import lru_cache

@lru_cache(None)
def win(a: int, b: int) -> bool:
    # ensure a >= b by swapping if needed
    if a < b:
        return not win(b, a)
    # if mod‐move kills your pile, you win instantly
    if a % b == 0:
        return True

    # 1) try the mod‐move → (b, a % b)
    r = a % b
    if not win(b, r):
        return True

    # 2) try the decrement‐move → (b, a-1)
    #    opponent sees (b, a-1), so we win if that state is losing
    if a - 1 < b:
        # roles swap again 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():
    A, B = map(int, sys.stdin.read().split())
    print("Alice" if win(A, B) else "Bob")

if __name__ == "__main__":
    main()
0