結果

問題 No.7 プライムナンバーゲーム
ユーザー kotatsugamekotatsugame
提出日時 2017-09-19 00:40:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 400 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 66,660 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 15:37:04
合計ジャッジ時間 4,161 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
6,812 KB
testcase_01 AC 152 ms
6,816 KB
testcase_02 AC 153 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 152 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 152 ms
6,940 KB
testcase_08 AC 153 ms
6,944 KB
testcase_09 AC 153 ms
6,944 KB
testcase_10 WA -
testcase_11 AC 152 ms
6,944 KB
testcase_12 AC 152 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 153 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
int memo[10001],p[10000],c;
bool f(int a)
{
	if(memo[a])return memo[a]>0;
	bool win=false;
	for(int i=0;i<c&&p[i]<=a-2;i++)
	{
		win|=!f(a-p[i]);
	}
	memo[a]=win?1:-1;
	return win;
}
int main()
{
	for(int i=2;i<=10000;i++)
	{
		bool flag=true;
		for(int j=2;j<i;j++)
		{
			flag&=i%j;
		}
		if(flag)p[c++]=i;
	}
	int n;cin>>n;cout<<(f(n)?"Win":"Lose")<<endl;
}
0