結果

問題 No.7 プライムナンバーゲーム
ユーザー yudedakoyudedako
提出日時 2016-03-16 22:48:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 811 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 61,280 KB
実行使用メモリ 6,692 KB
最終ジャッジ日時 2024-04-09 03:56:54
合計ジャッジ時間 1,241 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

std::vector<int> cul_prime() {
	bool array[10001]{ false };
	int sum = 0;
	for (auto i = 2; i <= 10000; ++i) {
		if (!array[i]) {
			++sum;
			for (auto j = 2; j <= 10000 / i; ++j) {
				array[i * j] = true;
			}
		}
	}
	std::vector<int> res(sum);
	int idx = 0;
	for (auto i = 2; i <= 10000; ++i) {
		if (!array[i]) res.at(idx++) = i;
	}
	return res;
}
int main() {
	bool must_lose[10001]{ false };
	must_lose[0] = true; must_lose[1] = true;
	auto prime = cul_prime();
	for (auto i = 0; i <= 10000; ++i) {
		if (!must_lose[i]) {
			for (auto j = 0; j < prime.size() && prime[j] <= 10000 - i; ++j) {
 				must_lose[i + prime[j]] = true;
			}
		}
	}
	int n;
	std::cin >> n;
	if (!must_lose[n]) std::cout << "Lose\n";
	else std::cout << "Win\n";
	return 0;
}
0