結果

問題 No.102 トランプを奪え
ユーザー otoshigootoshigo
提出日時 2024-01-27 18:13:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 5,000 ms
コード長 2,886 bytes
コンパイル時間 876 ms
コンパイル使用メモリ 79,516 KB
実行使用メモリ 23,388 KB
最終ジャッジ日時 2024-01-27 18:13:36
合計ジャッジ時間 2,258 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 8 ms
8,708 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 3 ms
6,548 KB
testcase_05 AC 19 ms
11,152 KB
testcase_06 AC 16 ms
8,612 KB
testcase_07 AC 7 ms
12,304 KB
testcase_08 AC 27 ms
19,852 KB
testcase_09 AC 221 ms
23,388 KB
testcase_10 AC 196 ms
23,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const int INF=1<<30;
bool check[14][14][14][14][53][2];
int dp[14][14][14][14][53][2];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int>N(4);
    for(int i=0;i<4;i++)cin>>N[i];
    auto f=[&](auto f,int a,int b,int c,int d,int x,bool flag)->int {
        if(check[a][b][c][d][x][flag])return dp[a][b][c][d][x][flag];
        check[a][b][c][d][x][flag]=true;
        int y=(N[0]+N[1]+N[2]+N[3]-a-b-c-d)-x;
        if(a==0&&b==0&&c==0&&d==0){
            dp[a][b][c][d][x][flag]=x-y;
            return x-y;
        }
        int diff=0;
        if(flag)diff=-INF;
        else diff=INF;
        vector<int>v={a,b,c,d};
        for(int i=0;i<4;i++){
            for(int t=1;t<=3;t++){
                if(v[i]<t)break;
                if(v[i]==t){
                    if(flag){
                        if(i==0)chmax(diff,t+2*((y+1)/2)+f(f,a-t,b,c,d,x+t+(y+1)/2,!flag));
                        else if(i==1)chmax(diff,t+2*((y+1)/2)+f(f,a,b-t,c,d,x+t+(y+1)/2,!flag));
                        else if(i==2)chmax(diff,t+2*((y+1)/2)+f(f,a,b,c-t,d,x+t+(y+1)/2,!flag));
                        else chmax(diff,t+2*((y+1)/2)+f(f,a,b,c,d-t,x+t+(y+1)/2,!flag));
                    }else{
                        if(i==0)chmin(diff,-t-2*((x+1)/2)+f(f,a-t,b,c,d,x-(x+1)/2,!flag));
                        else if(i==1)chmin(diff,-t-2*((x+1)/2)+f(f,a,b-t,c,d,x-(x+1)/2,!flag));
                        else if(i==2)chmin(diff,-t-2*((x+1)/2)+f(f,a,b,c-t,d,x-(x+1)/2,!flag));
                        else chmin(diff,-t-2*((x+1)/2)+f(f,a,b,c,d-t,x-(x+1)/2,!flag));
                    }
                }else{
                    if(flag){
                        if(i==0)chmax(diff,t+f(f,a-t,b,c,d,x+t,!flag));
                        else if(i==1)chmax(diff,t+f(f,a,b-t,c,d,x+t,!flag));
                        else if(i==2)chmax(diff,t+f(f,a,b,c-t,d,x+t,!flag));
                        else chmax(diff,t+f(f,a,b,c,d-t,x+t,!flag));
                    }else{
                        if(i==0)chmin(diff,-t+f(f,a-t,b,c,d,x,!flag));
                        else if(i==1)chmin(diff,-t+f(f,a,b-t,c,d,x,!flag));
                        else if(i==2)chmin(diff,-t+f(f,a,b,c-t,d,x,!flag));
                        else chmin(diff,-t+f(f,a,b,c,d-t,x,!flag));
                    }
                }
            }
        }
        dp[a][b][c][d][x][flag]=diff;
        return diff;
    };
    int diff=f(f,N[0],N[1],N[2],N[3],0,true);
    if(diff>0)cout<<"Taro\n";
    else if(diff<0)cout<<"Jiro\n";
    else cout<<"Draw\n";
}
0