結果

問題 No.7 プライムナンバーゲーム
ユーザー dekueuedekueue
提出日時 2017-02-11 12:36:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 92,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 20:46:59
合計ジャッジ時間 1,609 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int pri[10001];
int ps;
int p[10001];
int saiki(int u){
	if(u<2)
		return true;
	if(p[u]!=-1)
		return p[u];
	bool f=false;
	for(int i=0;i<ps&&pri[i]<=u;i++){
		f|=!saiki(u-pri[i]);
	}
	p[u]=f;
	return f;
}
signed main(){
	int n;
	fill(p,p+10001,-1);
	for(int i=2;i<10001;i++){
		bool f=true;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f=false;
				break;
			}
		}
		if(f)
			pri[ps++]=i;
	}
	const char *wl[2]={"Lose","Win"};
	cin>>n;
	cout<<wl[saiki(n)]<<endl;
}
0