結果

問題 No.102 トランプを奪え
ユーザー purple_jwlpurple_jwl
提出日時 2015-03-23 23:58:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 1,713 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 145,052 KB
実行使用メモリ 14,396 KB
最終ジャッジ日時 2023-09-11 09:49:41
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,296 KB
testcase_01 AC 5 ms
14,240 KB
testcase_02 AC 7 ms
14,180 KB
testcase_03 AC 6 ms
14,308 KB
testcase_04 AC 5 ms
14,176 KB
testcase_05 AC 9 ms
14,228 KB
testcase_06 AC 8 ms
14,236 KB
testcase_07 AC 6 ms
14,196 KB
testcase_08 AC 10 ms
14,240 KB
testcase_09 AC 51 ms
14,180 KB
testcase_10 AC 46 ms
14,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for(int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int memo[15][15][15][15][55];

int rec(int n1, int n2, int n3, int n4, int n, int total) {
  if(memo[n1][n2][n3][n4][n] != -1) return memo[n1][n2][n3][n4][n];

  int rival = total - n1 - n2 - n3 - n4 - n;
  int res = -1;
  int tmp;
  bool flg = false;

  REP(i, 1, 4) if(n1 >= i) {
    flg = true;
    tmp = 1;
    if(n1 == i) tmp = 2;
    res = max(res, abs(2 - rec(n1 - i, n2, n3, n4, rival / tmp, total)));
  }

  REP(i, 1, 4) if(n2 >= i) {
    flg = true;
    tmp = 1;
    if(n2 == i) tmp = 2;
    res = max(res, abs(2 - rec(n1, n2 - i, n3, n4, rival / tmp, total)));
  }

  REP(i, 1, 4) if(n3 >= i) {
    flg = true;
    tmp = 1;
    if(n3 == i) tmp = 2;
    res = max(res, abs(2 - rec(n1, n2, n3 - i, n4, rival / tmp, total)));
  }

  REP(i, 1, 4) if(n4 >= i) {
    flg = true;
    tmp = 1;
    if(n4 == i) tmp = 2;
    res = max(res, abs(2 - rec(n1, n2, n3, n4 - i, rival / tmp, total)));
  }

  if(!flg) {
    if(n > rival) res = 2;
    else if(n < rival) res = 0;
    else res = 1;
  }

  return memo[n1][n2][n3][n4][n] = res;
}

int main() {
  // ios_base::sync_with_stdio(false);
  int n1, n2, n3, n4;
  cin >> n1 >> n2 >> n3 >> n4;
  memset(memo, -1, sizeof(memo));
  int ans = rec(n1, n2, n3, n4, 0, n1 + n2 + n3 + n4);
  if(ans == 2) cout << "Taro" << endl;
  if(ans == 0) cout << "Jiro" << endl;
  if(ans == 1) cout << "Draw" << endl;
  return 0;
}
0