結果

問題 No.7 プライムナンバーゲーム
ユーザー erieri
提出日時 2015-07-24 03:37:16
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 685 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 65,596 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 22:01:42
合計ジャッジ時間 1,519 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

vector<int> eratosthenes(int n){
	vector<bool> arr(n);
	vector<int> prime(n);
	for (int i = 0; i < n; i++) arr[i] = true;

	for (int i = 2; i < sqrt(n); i++){
		if (arr[i]){
			for (int j = 0; i * (j + 2) < n; j++){
				arr[i *(j + 2)] = false;
			}
		}
	}
	int j = 0;
	for (int i = 2; i < n; i++){ if (arr[i]){ prime[j++] = i; } }
	return prime;
}
bool dp[10005] = { true, true };
int main(){
	auto prime = eratosthenes(10005);
	int n; cin >> n;
	for (int i = 2; i <= n; i++){
		for (int j: prime){
			if (i - j < 0) break;
			dp[i] |= !dp[i - j];
		}
	}
	cout << (dp[n] ? "Win" : "Lose") << endl;
	return 0;
}
0