結果

問題 No.102 トランプを奪え
ユーザー hotpepsihotpepsi
提出日時 2014-12-15 00:19:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 854 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 66,576 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-02 14:34:20
合計ジャッジ時間 1,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <string.h>

using namespace std;

int memo[16][16][16][16];

int dfs(int *N)
{
	int a[4] = { N[0], N[1], N[2], N[3] };
	sort(a, a + 4);
	if (memo[a[0]][a[1]][a[2]][a[3]] >= 0) {
		return memo[a[0]][a[1]][a[2]][a[3]];
	}
	if (a[2] == 0 && a[3] <= 3) {
		return 1;
	}
	int w = 0;
	for (int i = 0; i < 4; ++i) {
		for (int j = 1; j <= 3; ++j) {
			if (a[i] >= j) {
				a[i] -= j;
				if (dfs(a) == 0) {
					w = 1;
				}
				a[i] += j;
			}
		}
	}

	memo[a[0]][a[1]][a[2]][a[3]] = w;
	return w;
}

int main(int argc, char *argv[])
{
	memset(memo, -1, sizeof(memo));
	string s;
	getline(cin, s);
	stringstream ss(s);
	int N[4];
	ss >> N[0] >> N[1] >> N[2] >> N[3];
	cout << (dfs(N) ? "Taro" : "Jiro") << endl;
	return 0;
}
0