結果
| 問題 | No.102 トランプを奪え | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 18:51:33 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,035 bytes | 
| コンパイル時間 | 202 ms | 
| コンパイル使用メモリ | 82,364 KB | 
| 実行使用メモリ | 57,180 KB | 
| 最終ジャッジ日時 | 2025-06-12 18:51:35 | 
| 合計ジャッジ時間 | 1,364 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 3 WA * 5 | 
ソースコード
import sys
from functools import lru_cache
def main():
    n = list(map(int, sys.stdin.readline().split()))
    n1, n2, n3, n4 = n[0], n[1], n[2], n[3]
    @lru_cache(maxsize=None)
    def can_win(piles, t, j, is_taro_turn):
        # Check if all piles are empty
        if sum(piles) == 0:
            if t > j:
                return 1  # Taro wins
            elif t < j:
                return -1  # Jiro wins
            else:
                return 0  # Draw
        current_piles = list(piles)
        for i in range(4):
            if current_piles[i] == 0:
                continue
            for take in range(1, 4):
                if take > current_piles[i]:
                    continue
                new_piles = list(current_piles)
                new_piles[i] -= take
                new_piles_tuple = tuple(new_piles)
                if is_taro_turn:
                    new_t = t + take
                    new_j = j
                    if new_piles[i] == 0:
                        stolen = (new_j + 1) // 2
                        new_t += stolen
                        new_j -= stolen
                    next_turn = False
                    res = can_win(new_piles_tuple, new_t, new_j, next_turn)
                    if res == 1:
                        return 1
                else:
                    new_t = t
                    new_j = j + take
                    if new_piles[i] == 0:
                        stolen = (new_t + 1) // 2
                        new_j += stolen
                        new_t -= stolen
                    next_turn = True
                    res = can_win(new_piles_tuple, new_t, new_j, next_turn)
                    if res == 1:
                        return 1
        # If all moves lead to the opponent winning, current player loses
        return -1
    result = can_win((n1, n2, n3, n4), 0, 0, True)
    if result == 1:
        print("Taro")
    elif result == -1:
        print("Jiro")
    else:
        print("Draw")
if __name__ == "__main__":
    main()
            
            
            
        