結果
| 問題 |
No.102 トランプを奪え
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-06 21:06:22 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 465 ms / 5,000 ms |
| コード長 | 2,324 bytes |
| コンパイル時間 | 2,750 ms |
| コンパイル使用メモリ | 214,892 KB |
| 最終ジャッジ日時 | 2025-01-16 18:31:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
ソースコード
#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;
}