結果

問題 No.102 トランプを奪え
ユーザー fumofumofunifumofumofuni
提出日時 2020-12-06 21:06:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 438 ms / 5,000 ms
コード長 2,324 bytes
コンパイル時間 2,667 ms
コンパイル使用メモリ 224,660 KB
実行使用メモリ 14,052 KB
最終ジャッジ日時 2023-10-17 15:31:27
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 29 ms
4,776 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 79 ms
6,208 KB
testcase_06 AC 86 ms
6,452 KB
testcase_07 AC 23 ms
4,548 KB
testcase_08 AC 118 ms
7,356 KB
testcase_09 AC 438 ms
14,052 KB
testcase_10 AC 417 ms
13,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll sum=0;
map<vl,ll> memo;//Taroの手札,値が0=Draw,1=Taro,-1=Jiro;
ll dfs(vl v){
    sort(v.begin(),v.begin()+4);
    if(memo.count(v))return memo[v];
    ll x=sum;rep(i,5)x-=v[i];//x=Jiroの手札
    unordered_set<ll> st;
    rep(i,4){
        for(int j=1;j<=3;j++){
            vl newv=v;newv[i]-=j;
            if(newv[i]<0)break;
            //rep(k,4)cout << newv[k] <<" ";cout << endl;
            if(newv[i]==0){
                if(newv[5]==1)newv[4]+=(x+1)/2;
                if(newv[5]==-1)newv[4]/=2;
            }
            if(newv[5]==1)newv[4]+=j;
            newv[5]*=-1;
            st.ins(dfs(newv));
        }
    }
    if(st.count(v[5]))memo[v]=v[5];
    else if(st.count(0))memo[v]=0;
    else memo[v]=-v[5];
    return memo[v];
}
int main(){
    vl v(6);rep(i,4)cin >> v[i];
    rep(i,4)sum+=v[i];
    rep(i,sum+1){
        vector<ll> vv(6);vv[4]=i;vv[5]=1;
        rep(j,2){
            vv[5]*=-1;
            if(i==sum-i)memo[vv]=0;
            else if(i<sum-i)memo[vv]=-1;
            else memo[vv]=1;
        }
    }
    v[5]=1;
    //cout << dfs(v) <<endl;
    /*for(auto p:memo){
        for(auto z:p.fi)cout << z <<" ";cout << p.se <<endl;
    }*/
    ll p=dfs(v);
    if(p==1)cout << "Taro" <<endl;
    else if(p==-1)cout << "Jiro" <<endl;
    else cout << "Draw" <<endl;
}   
0