結果

問題 No.102 トランプを奪え
ユーザー data9824data9824
提出日時 2015-06-24 00:29:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 1,303 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 62,152 KB
実行使用メモリ 108,868 KB
最終ジャッジ日時 2023-09-22 00:20:35
合計ジャッジ時間 2,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
108,700 KB
testcase_01 AC 83 ms
108,740 KB
testcase_02 AC 83 ms
108,712 KB
testcase_03 AC 83 ms
108,740 KB
testcase_04 AC 82 ms
108,804 KB
testcase_05 AC 84 ms
108,796 KB
testcase_06 AC 85 ms
108,760 KB
testcase_07 AC 83 ms
108,780 KB
testcase_08 AC 84 ms
108,708 KB
testcase_09 AC 89 ms
108,708 KB
testcase_10 AC 89 ms
108,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>

using namespace std;

char cache[14][14][14][14][53][53];

int turn(const int cards[], int hand1, int hand2) {
	if ((cards[0] | cards[1] | cards[2] | cards[3]) == 0) {
		if (hand1 > hand2) {
			return 1;
		} else if (hand1 == hand2) {
			return 0;
		} else {
			return -1;
		}
	}
	int newCards[4];
	copy(&cards[0], &cards[3] + 1, &newCards[0]);
	sort(&newCards[0], &newCards[3] + 1);
	if (cache[newCards[0]][newCards[1]][newCards[2]][newCards[3]][hand1][hand2] != -2) {
		return cache[newCards[0]][newCards[1]][newCards[2]][newCards[3]][hand1][hand2];
	}
	int win = -1;
	for (int i = 0; i < 4 && win != 1; ++i) {
		for (int k = 1; k <= 3 && win != 1; ++k) {
			if (newCards[i] >= k) {
				newCards[i] -= k;
				int drawn;
				if (newCards[i] == 0) {
					drawn = (hand2 + 1) / 2;
				} else {
					drawn = 0;
				}
				win = turn(newCards, hand2 - drawn, hand1 + k + drawn) * -1;
				newCards[i] += k;
			}
		}
	}
	cache[newCards[0]][newCards[1]][newCards[2]][newCards[3]][hand1][hand2] = win;
	return win;
}

int main() {
	fill(&cache[0][0][0][0][0][0], &cache[13][13][13][13][52][52] + 1, -2);
	int n[4];
	cin >> n[0] >> n[1] >> n[2] >> n[3];
	int result = turn(n, 0, 0);
	cout << (result == 1 ? "Taro" : result == -1 ? "Jiro" : "Draw") << endl;
	return 0;
}
0