結果

問題 No.7 プライムナンバーゲーム
ユーザー chocoruskchocorusk
提出日時 2018-06-24 04:31:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 75,824 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:10:27
合計ジャッジ時間 1,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> p;
	p.push_back(2);
	for(int i=3; i<=n+100; i+=2){
		bool e=0;
		for(int j=3; j*j<=i; j+=2){
			if(i%j==0){
				e=1;
				break;
			}
		}
		if(e==0){
			p.push_back(i);
		}
	}
	bool dp[10001];
	dp[0]=0, dp[1]=0;
	int t=0;
	for(int i=2; i<=n; i++){
		if(p[t+1]<=i) t++;
		dp[i]=1;
		for(int j=0; j<=t; j++){
			if(dp[i-p[j]]==1){
				dp[i]=0;
				break;
			}
		}
	}
	if(dp[n]==0){
		printf("Win\n");
	}else{
		printf("Lose\n");
	}
	return 0;
}
0