結果

問題 No.102 トランプを奪え
ユーザー kk
提出日時 2021-04-19 06:04:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 382 ms / 5,000 ms
コード長 1,529 bytes
コンパイル時間 3,263 ms
コンパイル使用メモリ 201,352 KB
実行使用メモリ 491,116 KB
最終ジャッジ日時 2023-09-17 08:14:32
合計ジャッジ時間 6,350 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 220 ms
490,888 KB
testcase_01 AC 382 ms
490,956 KB
testcase_02 AC 226 ms
490,912 KB
testcase_03 AC 184 ms
491,116 KB
testcase_04 AC 167 ms
490,832 KB
testcase_05 AC 168 ms
490,912 KB
testcase_06 AC 169 ms
490,972 KB
testcase_07 AC 163 ms
490,884 KB
testcase_08 AC 173 ms
490,956 KB
testcase_09 AC 300 ms
490,836 KB
testcase_10 AC 285 ms
490,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dp[14][14][14][14][57][57];

int solve(int x, int y, int z, int w, int me, int you, int all) {
  if (dp[x][y][z][w][me][you] != -1)
    return dp[x][y][z][w][me][you];

  if (x + y + z + w == 0)
    return me;
  int ret = 0;
  
  for (int i = 1; i <= 3 && x >= i; i++) {
    if (i == x)
      ret = max(ret, all-solve(x-i, y, z, w, you/2, me+i+you-you/2, all));
    else
      ret = max(ret, all-solve(x-i, y, z, w, you, me+i, all));
  }

  for (int i = 1; i <= 3 && y >= i; i++) {
    if (i == y)
      ret = max(ret, all-solve(x, y-i, z, w, you/2, me+i+you-you/2, all));
    else
      ret = max(ret, all-solve(x, y-i, z, w, you, me+i, all));
  }

  for (int i = 1; i <= 3 && z >= i; i++) {
    if (i == z)
      ret = max(ret, all-solve(x, y, z-i, w, you/2, me+i+you-you/2, all));
    else
      ret = max(ret, all-solve(x, y, z-i, w, you, me+i, all));
  }

  for (int i = 1; i <= 3 && w >= i; i++) {
    if (i == w)
      ret = max(ret, all-solve(x, y, z, w-i, you/2, me+i+you-you/2, all));
    else
      ret = max(ret, all-solve(x, y, z, w-i, you, me+i, all));
  }

  return dp[x][y][z][w][me][you] = ret;
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  memset(dp, -1, sizeof(dp));
  
  int x, y, z, w;
  cin >> x >> y >> z >> w;

  int me = solve(x, y, z, w, 0, 0, x+y+z+w);
  int you = x + y + z + w - me;
  if (me > you)
    cout << "Taro" << endl;
  else if (you > me)
    cout << "Jiro" << endl;
  else
    cout << "Draw" << endl;
  
  return 0;
}
0