結果

問題 No.102 トランプを奪え
ユーザー しらっ亭しらっ亭
提出日時 2016-08-30 05:04:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 2,143 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 163,808 KB
実行使用メモリ 9,816 KB
最終ジャッジ日時 2024-04-26 17:26:03
合計ジャッジ時間 2,756 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,816 KB
testcase_01 AC 4 ms
9,752 KB
testcase_02 AC 7 ms
9,684 KB
testcase_03 AC 4 ms
9,736 KB
testcase_04 AC 5 ms
9,736 KB
testcase_05 AC 16 ms
9,660 KB
testcase_06 AC 13 ms
9,580 KB
testcase_07 AC 7 ms
9,512 KB
testcase_08 AC 19 ms
9,680 KB
testcase_09 AC 130 ms
9,536 KB
testcase_10 AC 116 ms
9,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
typedef long long ll;
typedef vector<int> vi;typedef vector<vi> vvi;typedef pair<int,int> pii;typedef vector<pii> vpii;

using T = int8_t;
using State = array<T, 5>;
T sum;

T dp[15][15][15][15][60][2];

// node: 状態
// depth: 手番。偶数は先手、奇数は後手。
T search(const State& node, int depth) {
  T &RET = dp[node[0]][node[1]][node[2]][node[3]][node[4]][depth%2];
  if (RET < 0x3f) return RET;

  bool pla = (depth % 2 == 0);
  bool e = 0;

  T mi = 100;
  T ma = -100;
  rep(i, 4) {
    rep(j, 1, 4) {
      if (node[i] >= j) {
        State next(node);
        next[i] -= j;
        if (pla) next[4] += j;

        if (next[i] == 0) {
          int n;
          if (pla) {
            n = sum;
            rep(i, 5) n -= next[i];
            next[4] += (n + 1) / 2;
          }
          else {
            next[4] -= (next[4]+1)/2;
          }
        }

        e = 1;
        T result = search(next, depth+1);
        mi = min(mi, result);
        ma = max(ma, result);
      }
    }
  }

  if (!e) return RET = 2 * node[4] - sum;
  return RET = pla ? ma : mi;
}

void Main() {
  int N1, N2, N3, N4;
  scanf("%d%d%d%d", &N1, &N2, &N3, &N4);
  memset(dp, 0x3f, sizeof(dp));

  sum = N1 + N2 + N3 + N4;

  State state;

  state[0] = N1;
  state[1] = N2;
  state[2] = N3;
  state[3] = N4;
  state[4] = 0;

  int8_t score = search(state, 0);
  if (score > 0) puts("Taro");
  else if (score < 0) puts("Jiro");
  else puts("Draw");
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
0