結果

問題 No.7 プライムナンバーゲーム
ユーザー amtgjwamtgjw
提出日時 2018-05-04 00:24:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 865 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 66,856 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:27:12
合計ジャッジ時間 1,826 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 35 ms
6,944 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 11 ms
6,944 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 16 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 8 ms
6,944 KB
testcase_12 AC 25 ms
6,944 KB
testcase_13 AC 27 ms
6,944 KB
testcase_14 AC 34 ms
6,948 KB
testcase_15 AC 33 ms
6,948 KB
testcase_16 AC 31 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define INF 		2000000007
#define MOD			1000000007

#define MAX 10005

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(f);i<(n);++i)

typedef unsigned long long int ull;

int main(){
	int N;cin >> N;

	vector<int> pn(MAX);
	REP(i,N+1) pn[i] = i;
	// エラトステネスの篩
	int cnt = 1;
	for(int i=4;i<N;i+=2) pn[i] = -1;
	for(int i=3;i<N;i+=2){
		if (pn[i]==-1) continue;
		for(int j=i*2;j<=N;j+=i) pn[j]= -1;
		++cnt;
	}
	// 整頓
	vector<int> p(cnt);
	for(int i=0,j=2;j<N;++j){
		if(pn[j]!=-1)p[i++]=j;
	}

	vector<bool> DP(MAX,true);
	DP[0] = DP[1] = true;
	
	for(int i=2;i<=N;++i){
		for(int j : p){
			if(i < j) break;
			DP[i] = DP[i] & DP[i-j];
		}
		DP[i] = !DP[i];
	}
	if(DP[N]) printf("Win\n");
	else printf("Lose\n");

	return 0;
}
0