結果

問題 No.102 トランプを奪え
ユーザー chocorusk
提出日時 2020-09-13 08:08:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 2,891 ms / 5,000 ms
コード長 1,054 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 61,348 KB
最終ジャッジ日時 2024-06-11 14:53:04
合計ジャッジ時間 6,915 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
dp={}
def solve(a, r):
    if (a, r) in dp:
        return dp[(a, r)]
    s=sum(a)
    if s==0:
        if r[0]>r[1]:
            dp[(a, r)]=1
            return 1
        elif r[0]==r[1]:
            dp[(a, r)]=0
            return 0
        else:
            dp[(a, r)]=-1
            return -1
    ans=-1
    for i in range(4):
        for x in range(1, 4):
            if x>a[i]:
                break
            b=list(a)
            b[i]-=x
            r1=list(r)[::-1]
            r1[1]+=x
            if b[i]==0:
                z=(r1[0]+1)//2
                r1[0]-=z
                r1[1]+=z
            t=solve(tuple(b), tuple(r1))
            if t==-1:
                dp[(a, r)]=1
                return 1
            elif t==0:
                ans=0
    dp[a]=ans
    return ans
n=tuple(map(int, readline().split()))
s=sum(n)
r=(0, 0)
a=solve(n, r)
if a==-1:
    print("Jiro")
elif a==0:
    print("Draw")
else:
    print("Taro")
0