結果

問題 No.102 トランプを奪え
ユーザー momoyuu
提出日時 2024-07-29 21:43:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 2,565 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 93,144 KB
実行使用メモリ 645,300 KB
最終ジャッジ日時 2024-07-29 21:43:32
合計ジャッジ時間 5,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;

int memo[14][14][14][14][60][60],vis[14][14][14][14][60][60];

int calc(int a,int b,int c,int d,int x,int y) {
    if(vis[a][b][c][d][x][y]++) return memo[a][b][c][d][x][y];

    if(a+b+c+d==0) {
        if(x>y) return memo[a][b][c][d][x][y] = 1;
        if(x==y) return memo[a][b][c][d][x][y] = 0;
        return memo[a][b][c][d][x][y] = -1;
    }
    int p = 0;
    int q = 0;
    int r = 0;

    if(a){
        for(int i = 1;i<=3;i++){
            if(i>a) continue;
            int nx = x + i;
            int ny = y;
            if(a==i){
                int get = (ny+1) / 2;
                ny -= get;
                nx += get;
            }
            swap(nx,ny);
            int ans = calc(a-i,b,c,d,nx,ny);
            if(ans==-1) p++;
            else if(ans==0) q++;
            else r++;
        }
    }
    if(b){
        for(int i = 1;i<=3;i++){
            if(i>b) continue;
            int nx = x + i;
            int ny = y;
            if(b==i){
                int get = (ny+1) / 2;
                ny -= get;
                nx += get;
            }
            swap(nx,ny);

            int ans = calc(a,b-i,c,d,nx,ny);
            if(ans==-1) p++;
            else if(ans==0) q++;
            else r++;
        }
    }
    if(c){
        for(int i = 1;i<=3;i++){
            if(i>c) continue;
            int nx = x + i;
            int ny = y;
            if(c==i){
                int get = (ny+1) / 2;
                ny -= get;
                nx += get;
            }
            swap(nx,ny);

            int ans = calc(a,b,c-i,d,nx,ny);
            if(ans==-1) p++;
            else if(ans==0) q++;
            else r++;
        }
    }

    if(d){
        for(int i = 1;i<=3;i++){
            if(i>d) continue;
            int nx = x + i;
            int ny = y;
            if(d==i){
                int get = (ny+1) / 2;
                ny -= get;
                nx += get;
            }
            swap(nx,ny);

            int ans = calc(a,b,c,d-i,nx,ny);
            if(ans==-1) p++;
            else if(ans==0) q++;
            else r++;
        }
    }
    if(p) return memo[a][b][c][d][x][y] = 1;
    if(q) return memo[a][b][c][d][x][y] = 0;
    return memo[a][b][c][d][x][y] = -1;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int a,b,c,d;
    cin>>a>>b>>c>>d;

    int ans = calc(a,b,c,d,0,0);
    if(ans==1) cout<<"Taro\n";
    else if(ans==0) cout<<"Draw\n";
    else cout<<"Jiro\n";

}

0