結果

問題 No.102 トランプを奪え
ユーザー mizunomidorimizunomidori
提出日時 2016-07-06 03:31:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,825 bytes
コンパイル時間 548 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 139,596 KB
最終ジャッジ日時 2024-04-20 22:07:26
合計ジャッジ時間 1,680 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>

using namespace std;

enum result {UNDEFINED, WIN, LOSE, DRAW};

result dp[53][53][14][14][14][14];

result solve(int p1, int p2, const vector<int> &N)
{
    if (dp[p1][p2][N[0]][N[1]][N[2]][N[3]] != UNDEFINED) {
        return dp[p1][p2][N[0]][N[1]][N[2]][N[3]];
    }
    result ret = LOSE;
    for (int k = 0; k < 4; k++) {
        for (int i = 1; i <= min(3, N[k]); i++) {
            vector<int> M(N);
            M[k] -= i;
            result res;
            if (i == N[k]) {
                int p2_half = (p2 + 1) / 2;
                res = solve(p2 - p2_half, p1 + i + p2_half, M);
            } else {
                res = solve(p2, p1 + i, M);
            }
            if (res == LOSE) {
                return dp[p1][p2][N[0]][N[1]][N[2]][N[3]] = WIN;
            } else if (res == DRAW) {
                ret = DRAW;
            }
        }
    }
    return dp[p1][p2][N[0]][N[1]][N[2]][N[3]] = ret;
}

int main(void)
{
    for (int i = 0; i <= 52; i++) {
        for (int j = 0; j <= 52; j++) {
            if (i > j) {
                dp[i][j][0][0][0][0] = WIN;
            } else if (i < j) {
                dp[i][j][0][0][0][0] = LOSE;
            } else {
                dp[i][j][0][0][0][0] = DRAW;
            }
        }
    }
    vector<int> N(4);
    for (int i = 0; i < 4; i++) {
        cin >> N[i];
    }
    result res = solve(0, 0, N);
    if (res == WIN) {
        printf("TARO\n");
    } else if (res == LOSE) {
        printf("JIRO\n");
    } else {
        printf("DRAW\n");
    }
    return 0;
}
0