結果

問題 No.102 トランプを奪え
ユーザー tkzw_21tkzw_21
提出日時 2015-01-05 20:36:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,347 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 64,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 22:03:30
合計ジャッジ時間 1,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
int memo[2][14][14][14][14];

bool dfs(int t,int n1,int n2,int n3,int n4){
	if(memo[t%2][n1][n2][n3][n4] != 0){
		if(memo[t%2][n1][n2][n3][n4] == 1)return true;
		else return false;
	}
	if(n1+n2+n3+n4==0)return t%2==0?false:true;
	bool ret;

	if(t%2==0){
	ret = false;
	for(int i=1;i<=3;i++){
		if(n1-i>=0)ret |= dfs(t+1,n1-i,n2,n3,n4);
		if(n2-i>=0)ret |= dfs(t+1,n1,n2-i,n3,n4);
		if(n3-i>=0)ret |= dfs(t+1,n1,n2,n3-i,n4);
		if(n4-i>=0)ret |= dfs(t+1,n1,n2,n3,n4-i);
	}
	}	
	else{
	ret = true;
	for(int i=1;i<=3;i++){
		if(n1-i>=0)ret &= dfs(t+1,n1-i,n2,n3,n4);
		if(n2-i>=0)ret &= dfs(t+1,n1,n2-i,n3,n4);
		if(n3-i>=0)ret &= dfs(t+1,n1,n2,n3-i,n4);
		if(n4-i>=0)ret &= dfs(t+1,n1,n2,n3,n4-i);
	}
	}
	if(ret)memo[t%2][n1][n2][n3][n4] = 1;
	else memo[t%2][n1][n2][n3][n4] = -1;
	return ret;
}

int main(void) {
	int n1,n2,n3,n4;
	cin >> n1 >> n2 >> n3 >> n4;
	if(dfs(0,n1,n2,n3,n4))cout << "Taro" << endl;
	else cout << "Jiro" << endl;
}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));
0