結果
| 問題 |
No.3112 Decrement or Mod Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-20 17:04:07 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,276 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2025-04-20 17:04:13 |
| 合計ジャッジ時間 | 5,204 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | RE * 65 |
ソースコード
def game_winner(A, B):
# DPテーブルの初期化
dp = [[False] * (B + 1) for _ in range(A + 1)]
# 0になったら負け
for i in range(A + 1):
dp[i][0] = False # Bobのターンで、Aliceが負ける
for j in range(B + 1):
dp[0][j] = True # Aliceのターンで、Bobが負ける
# 動的計画法で勝者を決定
for a in range(1, A + 1):
for b in range(1, B + 1):
# Aliceのターン
alice_can_win = False
# 1減らす場合
if a - 1 >= 0 and not dp[a-1][b]:
alice_can_win = True
# 相手の数で割った余りに変える場合
if b <= a and not dp[a % b][b]:
alice_can_win = True
# Bobのターン(反転)
# 1減らす場合
if b - 1 >= 0 and not dp[a][b-1]:
alice_can_win = True
# 相手の数で割った余りに変える場合
if a <= b and not dp[a][b % a]:
alice_can_win = True
dp[a][b] = alice_can_win
# 最後にAliceが勝つかどうか
return "Alice" if dp[A][B] else "Bob"
# AとBを入力
A, B = map(int, input().split())
print(game_winner(A, B))