結果

問題 No.7 プライムナンバーゲーム
ユーザー KKT89KKT89
提出日時 2020-06-08 06:26:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 706 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 85,536 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:55:06
合計ジャッジ時間 1,597 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int dp[10001];
bool is_not_prime[10001];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	dp[2]=dp[3]=0;
	vector<int> p;
	for(int i=2;i<=n;i++){
		if(!is_not_prime[i]){
			p.push_back(i);
			for(int j=i+i;j<=n;j+=i){
				is_not_prime[j]=1;
			}
		}
	}
	for(int i=4;i<=n;i++){
		bool ok=0;
		for(int j=0;j<p.size();j++){
			if(i-p[j]>=2){
				if(!dp[i-p[j]]){
					ok=1;
				}
			}else break;
		}
		if(ok)dp[i]=1;
	}
	if(!dp[n]){
		printf("Lose\n");
	}
	else{
		printf("Win\n");
	}
}
0