結果
問題 |
No.102 トランプを奪え
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:51:13 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,119 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 306,060 KB |
最終ジャッジ日時 | 2025-06-12 18:51:26 |
合計ジャッジ時間 | 12,526 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 TLE * 1 -- * 1 |
ソースコード
from functools import lru_cache def main(): import sys N = list(map(int, sys.stdin.readline().split())) S = sum(N) @lru_cache(maxsize=None) def evaluate(piles_tuple, t, turn): piles = list(piles_tuple) if all(n == 0 for n in piles): j = S - sum(piles) - t if t > j: return 'Taro' elif j > t: return 'Jiro' else: return 'Draw' possible_outcomes = [] for i in range(4): if piles[i] == 0: continue for take in range(1, 4): if take > piles[i]: continue new_piles = piles.copy() new_piles[i] -= take if new_piles[i] < 0: continue # This should never happen due to the take condition if turn == 0: new_t = t + take else: new_t = t # Jiro's hand is handled via the sum if new_piles[i] == 0: if turn == 0: j = S - sum(new_piles) - new_t stolen = (j + 1) // 2 new_t += stolen else: stolen = (new_t + 1) // 2 new_t -= stolen new_piles_tuple = tuple(new_piles) outcome = evaluate(new_piles_tuple, new_t, 1 - turn) possible_outcomes.append(outcome) if turn == 0: if 'Taro' in possible_outcomes: return 'Taro' if 'Draw' in possible_outcomes: return 'Draw' return 'Jiro' else: if 'Jiro' in possible_outcomes: return 'Jiro' if 'Draw' in possible_outcomes: return 'Draw' return 'Taro' initial_piles = tuple(N) result = evaluate(initial_piles, 0, 0) print(result) if __name__ == "__main__": main()