結果
問題 | No.102 トランプを奪え |
ユーザー | Mao-beta |
提出日時 | 2024-03-07 17:23:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,086 ms / 5,000 ms |
コード長 | 3,448 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 82,196 KB |
実行使用メモリ | 97,904 KB |
最終ジャッジ日時 | 2024-09-29 18:41:34 |
合計ジャッジ時間 | 4,128 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
57,048 KB |
testcase_01 | AC | 48 ms
58,288 KB |
testcase_02 | AC | 179 ms
79,268 KB |
testcase_03 | AC | 47 ms
57,020 KB |
testcase_04 | AC | 69 ms
71,196 KB |
testcase_05 | AC | 243 ms
79,908 KB |
testcase_06 | AC | 232 ms
80,268 KB |
testcase_07 | AC | 165 ms
79,360 KB |
testcase_08 | AC | 232 ms
80,600 KB |
testcase_09 | AC | 1,086 ms
97,904 KB |
testcase_10 | AC | 1,023 ms
96,884 KB |
ソースコード
import sys import math import bisect from heapq import heapify, heappop, heappush from collections import deque, defaultdict, Counter from functools import lru_cache from itertools import accumulate, combinations, permutations, product sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 MOD99 = 998244353 input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() SMI = lambda: input().split() SLI = lambda: list(SMI()) EI = lambda m: [NLI() for _ in range(m)] def main(): Ns = NLI() S = sum(Ns) # dp[n0][n1][n2][n3][h0] h1=S-(n0+n1+n2+n3) # 上の状態で回されたら勝てるか dp = [[[[[0]*(S+1) for _ in range(Ns[3]+1)] for _ in range(Ns[2]+1)] for _ in range(Ns[1]+1)] for _ in range(Ns[0]+1)] for h0 in range(S+1): h1 = S - h0 if h0 > h1: x = 1 elif h0 < h1: x = -1 else: x = 0 dp[0][0][0][0][h0] = x for n0 in range(Ns[0] + 1): for n1 in range(Ns[1] + 1): for n2 in range(Ns[2] + 1): for n3 in range(Ns[3] + 1): for h0 in range(S+1): if n0 == n1 == n2 == n3 == 0: continue h1 = S-(n0+n1+n2+n3) tmp = [] for k in range(1, 4): if n0-k > 0: d = dp[n0-k][n1][n2][n3][h1] elif n0-k == 0: d = dp[n0-k][n1][n2][n3][h1//2] else: break tmp.append(d) for k in range(1, 4): if n1-k > 0: d = dp[n0][n1-k][n2][n3][h1] elif n1-k == 0: d = dp[n0][n1-k][n2][n3][h1//2] else: break tmp.append(d) for k in range(1, 4): if n2-k > 0: d = dp[n0][n1][n2-k][n3][h1] elif n2-k == 0: d = dp[n0][n1][n2-k][n3][h1//2] else: break tmp.append(d) for k in range(1, 4): if n3-k > 0: d = dp[n0][n1][n2][n3-k][h1] elif n3-k == 0: d = dp[n0][n1][n2][n3-k][h1//2] else: break tmp.append(d) if -1 in tmp: dp[n0][n1][n2][n3][h0] = 1 elif 0 not in tmp: dp[n0][n1][n2][n3][h0] = -1 else: dp[n0][n1][n2][n3][h0] = 0 # print(h0, h1, n0, n1, n2, n3, dp[n0][n1][n2][n3][h0]) ans = dp[Ns[0]][Ns[1]][Ns[2]][Ns[3]][0] if ans == 1: print("Taro") elif ans == -1: print("Jiro") else: print("Draw") if __name__ == "__main__": main()