結果

問題 No.7 プライムナンバーゲーム
ユーザー halshiphalship
提出日時 2020-11-16 11:50:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 807 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 76,696 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:41:48
合計ジャッジ時間 1,974 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

void getPrimeNumbers(vector<int> & v, int n) {
	vector<bool> search(n + 1, true);
	for (int i = 2; i <= n; i++) {
		if (search[i] && i <= (int)sqrt(n)) {
			v.push_back(i);
			for (int j = i * 2; j <= n; j += i) {
				search[j] = false;
			}
		}
		else if (search[i]) {
			v.push_back(i);
		}
	}
}

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

	vector<int> primes;
	getPrimeNumbers(primes, n);

	vector<bool> dp(n + 1, false);
	dp[0] = true;
	dp[1] = true;
	for (int i = 2; i <= n; i++) {
		for (int p : primes) {
			if (p > i) {
				break;
			}
			if (!dp[i - p]) {
				dp[i] = true;
				break;
			}
		}
	}

	if (dp[n]) {
		cout << "Win\n";
	}
	else {
		cout << "Lose\n";
	}

	return 0;
}
0