結果
問題 | No.102 トランプを奪え |
ユーザー | mizunomidori |
提出日時 | 2016-07-06 03:32:47 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 115 ms / 5,000 ms |
コード長 | 1,825 bytes |
コンパイル時間 | 593 ms |
コンパイル使用メモリ | 81,424 KB |
実行使用メモリ | 52,736 KB |
最終ジャッジ日時 | 2024-04-20 22:07:27 |
合計ジャッジ時間 | 1,444 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 9 ms
14,720 KB |
testcase_01 | AC | 9 ms
14,848 KB |
testcase_02 | AC | 12 ms
16,896 KB |
testcase_03 | AC | 9 ms
14,720 KB |
testcase_04 | AC | 10 ms
14,976 KB |
testcase_05 | AC | 20 ms
20,352 KB |
testcase_06 | AC | 20 ms
19,968 KB |
testcase_07 | AC | 14 ms
17,536 KB |
testcase_08 | AC | 43 ms
34,816 KB |
testcase_09 | AC | 115 ms
52,736 KB |
testcase_10 | AC | 97 ms
48,512 KB |
ソースコード
#include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <ctime> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <iostream> #include <algorithm> #include <functional> #include <numeric> #include <string> using namespace std; enum result {UNDEFINED, WIN, LOSE, DRAW}; result dp[53][53][14][14][14][14]; result solve(int p1, int p2, const vector<int> &N) { if (dp[p1][p2][N[0]][N[1]][N[2]][N[3]] != UNDEFINED) { return dp[p1][p2][N[0]][N[1]][N[2]][N[3]]; } result ret = LOSE; for (int k = 0; k < 4; k++) { for (int i = 1; i <= min(3, N[k]); i++) { vector<int> M(N); M[k] -= i; result res; if (i == N[k]) { int p2_half = (p2 + 1) / 2; res = solve(p2 - p2_half, p1 + i + p2_half, M); } else { res = solve(p2, p1 + i, M); } if (res == LOSE) { return dp[p1][p2][N[0]][N[1]][N[2]][N[3]] = WIN; } else if (res == DRAW) { ret = DRAW; } } } return dp[p1][p2][N[0]][N[1]][N[2]][N[3]] = ret; } int main(void) { for (int i = 0; i <= 52; i++) { for (int j = 0; j <= 52; j++) { if (i > j) { dp[i][j][0][0][0][0] = WIN; } else if (i < j) { dp[i][j][0][0][0][0] = LOSE; } else { dp[i][j][0][0][0][0] = DRAW; } } } vector<int> N(4); for (int i = 0; i < 4; i++) { cin >> N[i]; } result res = solve(0, 0, N); if (res == WIN) { printf("Taro\n"); } else if (res == LOSE) { printf("Jiro\n"); } else { printf("Draw\n"); } return 0; }