結果

問題 No.102 トランプを奪え
ユーザー 👑 colognecologne
提出日時 2022-02-02 15:57:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 505 ms / 5,000 ms
コード長 1,417 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 86,348 KB
最終ジャッジ日時 2023-09-02 02:50:16
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,184 KB
testcase_01 AC 69 ms
71,540 KB
testcase_02 AC 199 ms
80,120 KB
testcase_03 AC 69 ms
71,272 KB
testcase_04 AC 70 ms
71,468 KB
testcase_05 AC 176 ms
78,624 KB
testcase_06 AC 182 ms
78,440 KB
testcase_07 AC 185 ms
80,664 KB
testcase_08 AC 335 ms
83,264 KB
testcase_09 AC 505 ms
86,348 KB
testcase_10 AC 450 ms
83,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys


def input(): return sys.stdin.readline().rstrip()


def main():

    A, B, C, D = sorted(map(int, input().split()), reverse=True)

    DP = [[[[[None]*(A-a+B-b+C-c+D-d+1) for d in range(min(D, c)+1)]
            for c in range(min(C, b)+1)] for b in range(min(B, a)+1)] for a in range(A+1)]

    tot = A+B+C+D

    def solve(a, b, c, d, e):
        if a == b == c == d == 0:
            return e

        a, b, c, d = sorted([a, b, c, d], reverse=True)

        if DP[a][b][c][d][e] is not None:
            return DP[a][b][c][d][e]

        opp = (A-a+B-b+C-c+D-d)-e
        ans = 0
        for i in range(1, min(3, a)+1):
            ans = max(ans, tot-solve(a-i, b, c, d,
                      opp if a != i else opp // 2))
        for i in range(1, min(3, b)+1):
            ans = max(ans, tot-solve(a, b-i, c, d,
                      opp if b != i else opp // 2))
        for i in range(1, min(3, c)+1):
            ans = max(ans, tot-solve(a, b, c-i, d,
                      opp if c != i else opp // 2))
        for i in range(1, min(3, d)+1):
            ans = max(ans, tot-solve(a, b, c, d-i,
                      opp if d != i else opp // 2))

        DP[a][b][c][d][e] = ans
        return ans

    ans = solve(A, B, C, D, 0)

    if ans > tot-ans:
        print('Taro')
    elif ans == tot-ans:
        print('Draw')
    else:
        print('Jiro')


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