結果

問題 No.102 トランプを奪え
ユーザー lam6er
提出日時 2025-04-15 21:35:23
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,847 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 134,508 KB
最終ジャッジ日時 2025-04-15 21:37:26
合計ジャッジ時間 11,394 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from functools import lru_cache

def main():
    sys.setrecursionlimit(1 << 25)
    n = list(map(int, sys.stdin.readline().split()))
    a, b, c, d = n

    @lru_cache(maxsize=None)
    def dfs(a, b, c, d, turn, taro, jiro):
        if a + b + c + d == 0:
            return taro - jiro

        best = -float('inf') if turn == 0 else float('inf')
        piles = [a, b, c, d]
        for i in range(4):
            if piles[i] == 0:
                continue
            for take in range(1, 4):
                if take > piles[i]:
                    break
                new_piles = list(piles)
                new_piles[i] -= take
                na, nb, nc, nd = new_piles
                new_taro, new_jiro = taro, jiro
                if turn == 0:
                    new_taro += take
                else:
                    new_jiro += take

                if new_piles[i] == 0:
                    if turn == 0:
                        steal = (new_jiro + 1) // 2
                        new_taro += steal
                        new_jiro -= steal
                    else:
                        steal = (new_taro + 1) // 2
                        new_jiro += steal
                        new_taro -= steal

                if turn == 0:
                    res = dfs(na, nb, nc, nd, 1, new_taro, new_jiro)
                    if res > best:
                        best = res
                else:
                    res = dfs(na, nb, nc, nd, 0, new_taro, new_jiro)
                    if res < best:
                        best = res
        return best if best != -float('inf') and best != float('inf') else 0

    total_diff = dfs(a, b, c, d, 0, 0, 0)
    if total_diff > 0:
        print("Taro")
    elif total_diff < 0:
        print("Jiro")
    else:
        print("Draw")

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