Submission #656510


Source Code Expand

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

int dp[505][1000];
//(残っている石の数,このターンで取れる石の個数の上限)
int rec(int now, int pre)
{
	if(dp[now][pre]>=0) return dp[now][pre];

	//このターンで勝ち確定
	if(pre>=now) return 1;

	//どこか1つでも(相手のターンで)負けに導ける選択肢があればこのターンで(自分が)勝てる
	int ret=0;
	for(int i=1; i<=pre; ++i)
	{
		if(now-i<0) break;
		ret|=!rec(now-i,i+1);
	}

	return dp[now][pre]=ret;
}

int main()
{
	int n,p;
	cin >>n >>p;
	memset(dp,-1,sizeof(dp));
	printf("%s\n",(rec(n,p)==1)?"first":"second");
}

Submission Info

Submission Time
Task G - 石取りゲーム
User imulan
Language C++11 (GCC 4.8.1)
Score 100
Code Size 885 Byte
Status AC
Exec Time 42 ms
Memory 3136 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 45
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All corner_01.txt, corner_02.txt, corner_03.txt, corner_04.txt, corner_05.txt, edge_113_2.txt, edge_113_3.txt, edge_120_39.txt, edge_120_40.txt, edge_140_19.txt, edge_140_20.txt, edge_15_4.txt, edge_15_5.txt, edge_20_19.txt, edge_20_20.txt, edge_400_79.txt, edge_400_80.txt, edge_455_4.txt, edge_455_5.txt, edge_500_19.txt, edge_500_20.txt, edge_50_10.txt, edge_50_9.txt, edge_5_4.txt, edge_5_5.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt
Case Name Status Exec Time Memory
corner_01.txt AC 32 ms 2992 KB
corner_02.txt AC 30 ms 2992 KB
corner_03.txt AC 30 ms 2976 KB
corner_04.txt AC 30 ms 3096 KB
corner_05.txt AC 31 ms 2992 KB
edge_113_2.txt AC 30 ms 2992 KB
edge_113_3.txt AC 28 ms 2992 KB
edge_120_39.txt AC 31 ms 2976 KB
edge_120_40.txt AC 31 ms 2900 KB
edge_140_19.txt AC 30 ms 2992 KB
edge_140_20.txt AC 30 ms 2996 KB
edge_15_4.txt AC 30 ms 2996 KB
edge_15_5.txt AC 28 ms 3088 KB
edge_20_19.txt AC 29 ms 2996 KB
edge_20_20.txt AC 30 ms 3080 KB
edge_400_79.txt AC 35 ms 2992 KB
edge_400_80.txt AC 36 ms 2992 KB
edge_455_4.txt AC 32 ms 2996 KB
edge_455_5.txt AC 30 ms 2996 KB
edge_500_19.txt AC 31 ms 2992 KB
edge_500_20.txt AC 32 ms 3136 KB
edge_50_10.txt AC 31 ms 2992 KB
edge_50_9.txt AC 31 ms 2992 KB
edge_5_4.txt AC 28 ms 3088 KB
edge_5_5.txt AC 30 ms 3088 KB
random_01.txt AC 41 ms 3092 KB
random_02.txt AC 31 ms 2996 KB
random_03.txt AC 42 ms 3084 KB
random_04.txt AC 37 ms 3092 KB
random_05.txt AC 29 ms 2992 KB
random_06.txt AC 31 ms 2996 KB
random_07.txt AC 36 ms 2996 KB
random_08.txt AC 36 ms 2996 KB
random_09.txt AC 28 ms 2992 KB
random_10.txt AC 40 ms 2992 KB
random_11.txt AC 30 ms 2996 KB
random_12.txt AC 30 ms 3092 KB
random_13.txt AC 31 ms 2996 KB
random_14.txt AC 30 ms 2996 KB
random_15.txt AC 31 ms 2976 KB
random_16.txt AC 30 ms 3096 KB
random_17.txt AC 37 ms 3080 KB
random_18.txt AC 34 ms 2996 KB
random_19.txt AC 31 ms 2992 KB
random_20.txt AC 29 ms 3000 KB
sample_01.txt AC 30 ms 2992 KB
sample_02.txt AC 30 ms 2992 KB
sample_03.txt AC 29 ms 2892 KB
sample_04.txt AC 30 ms 2992 KB