結果

問題 No.102 トランプを奪え
ユーザー tottoripapertottoripaper
提出日時 2014-12-14 23:41:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 1,511 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 39,740 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-02 14:32:41
合計ジャッジ時間 1,168 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,784 KB
testcase_01 AC 6 ms
10,904 KB
testcase_02 AC 8 ms
10,932 KB
testcase_03 AC 7 ms
10,896 KB
testcase_04 AC 7 ms
10,900 KB
testcase_05 AC 12 ms
10,844 KB
testcase_06 AC 11 ms
10,780 KB
testcase_07 AC 8 ms
10,808 KB
testcase_08 AC 13 ms
10,780 KB
testcase_09 AC 68 ms
10,792 KB
testcase_10 AC 63 ms
10,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>

int N[4];
int dp[14][14][14][14][53];
int sum;

int rec(int n1, int n2, int n3, int n4, int a){
    int b = sum - (n1 + n2 + n3 + n4 + a);
    if(n1 == 0 && n2 == 0 && n3 == 0 && n4 == 0){return a;}
    if(dp[n1][n2][n3][n4][a] != -1){return dp[n1][n2][n3][n4][a];}

    int res = 1001001001;
    for(int i=1;i<=3;i++){
        if(i <= n1){
            if(i == n1){res = std::min(res, rec(0, n2, n3, n4, b - (b+1) / 2));}
            else{res = std::min(res, rec(n1-i, n2, n3, n4, b));}
        }

        if(i <= n2){
            if(i == n2){res = std::min(res, rec(n1, 0, n3, n4, b - (b+1) / 2));}
            else{res = std::min(res, rec(n1, n2-i, n3, n4, b));}
        }

        if(i <= n3){
            if(i == n3){res = std::min(res, rec(n1, n2, 0, n4, b - (b+1) / 2));}
            else{res = std::min(res, rec(n1, n2, n3-i, n4, b));}
        }

        if(i <= n4){
            if(i == n4){res = std::min(res, rec(n1, n2, n3, 0, b - (b+1) / 2));}
            else{res = std::min(res, rec(n1, n2, n3, n4-i, b));}
        }
    }
    res = sum - res;

    return dp[n1][n2][n3][n4][a] = res;
}

int main(){
    for(int i=0;i<4;i++){scanf("%d", N+i); sum += N[i];}

    std::fill(&dp[0][0][0][0][0], &dp[0][0][0][0][0]+14*14*14*14*53, -1);

    if(rec(N[0], N[1], N[2], N[3], 0) >= (sum+1) / 2){
        puts("Taro");
    }else{
        puts("Jiro");
    }
    // printf("%d\n", rec(N[0], N[1], N[2], N[3], 0));
}
0