結果

問題 No.102 トランプを奪え
ユーザー mizunomidori
提出日時 2016-07-06 03:32:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 1,825 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 137,552 KB
最終ジャッジ日時 2024-10-12 20:25:06
合計ジャッジ時間 1,677 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

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