結果

問題 No.3112 Decrement or Mod Game
ユーザー Mistletoe
提出日時 2025-04-19 00:51:54
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2025-04-19 00:52:00
合計ジャッジ時間 5,583 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 3
other RE * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

def find_winner(A, B):
    # Create a DP table where dp[a][b] means if the current position is a winning position for Alice
    dp = [[False] * 19 for _ in range(19)]  # Since A and B are in the range [1, 18], we need a table of size 19x19
    
    # Base cases:
    for b in range(19):
        dp[0][b] = False  # If Alice has 0, Bob wins.
    
    for a in range(19):
        dp[a][0] = True  # If Bob has 0, Alice wins.

    # Fill the DP table for all values of a and b from 1 to 18
    for a in range(1, 19):
        for b in range(1, 19):
            # Alice's turn:
            # 1. Alice can reduce her number by 1, so we check if dp[a-1][b] is False (Bob loses)
            if not dp[a-1][b]:
                dp[a][b] = True
            # 2. Alice can divide her number by Bob's number, if a >= b
            if a >= b and not dp[a//b][b]:
                dp[a][b] = True

    # The result is determined by the value of dp[A][B]
    return "Alice" if dp[A][B] else "Bob"

# Read inputs
A = int(input())
B = int(input())

# Print the result
print(find_winner(A, B))
0