結果

問題 No.102 トランプを奪え
コンテスト
ユーザー Rumain831
提出日時 2026-08-12 15:48:15
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 57 ms / 5,000 ms
+ 154µs
コード長 1,065 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,665 ms
コンパイル使用メモリ 173,136 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2026-08-12 15:48:27
合計ジャッジ時間 4,086 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int dp[14][14][14][14][53];
int seen[14][14][14][14][53];
int n[5];

int main(void){
  int sum=0;
  for(int i=0; i<4; i++) cin >> n[i], sum+=n[i];
  auto dfs=[&](auto dfs, int x[5]){
    if(seen[x[0]][x[1]][x[2]][x[3]][x[4]]) return dp[x[0]][x[1]][x[2]][x[3]][x[4]];
    seen[x[0]][x[1]][x[2]][x[3]][x[4]]=1;
    if(x[0]==0&&x[1]==0&&x[2]==0&&x[3]==0){
      return dp[x[0]][x[1]][x[2]][x[3]][x[4]]=x[4];
    }
    int ans=-1e9;
    int opp=sum-x[0]-x[1]-x[2]-x[3]-x[4];
    for(int i=0; i<4; i++){
      int nx[5]={x[0], x[1], x[2], x[3], x[4]};
      for(int j=1; j<=3; j++){
        if(nx[i]<j) continue;
        nx[i]-=j;
        int no=opp;
        if(nx[i]==0) no=opp/2;
        nx[4]=no;
        ans=max(ans, sum-dfs(dfs, nx));
        nx[i]+=j;
      }
    }
    return dp[x[0]][x[1]][x[2]][x[3]][x[4]]=ans;
  };
  int taro=dfs(dfs, n), jiro=sum-taro;
  if(taro==jiro) cout << "Draw" << endl;
  else cout << (taro>jiro?"Taro":"Jiro") << endl;
  return 0; 
}
0