結果

問題 No.7 プライムナンバーゲーム
ユーザー furafyfurafy
提出日時 2015-07-29 15:33:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,056 bytes
コンパイル時間 1,187 ms
コンパイル使用メモリ 72,052 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 21:42:08
合計ジャッジ時間 2,408 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;
int which[10000];
bool prime[10000];

bool IsPrime(int n) {
	if (n == 2) return true;
	if (n % 2 == 0)  return false;
	int lim = n / 2;
	for (int i = 2; i < lim; i++) {
		if (n % i == 0) return false;
	}
	return true;
}

bool Solve(int n) {
	if (which[n] >= 0) {
		return which[n];
	}
	int ret = 0;
	for (int i = 0; i <= n; i++) {
		if (prime[i]) {
			if (Solve(n - i) == 0)
				ret = 1;
		}
	}
	return which[n] = ret;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//std::cout << std::fixed;
	memset(prime, false, sizeof(prime));
	memset(which, -1, sizeof(which));
	int N;
	cin >> N;
	for (int i = 2; i <= N; i++) {
		if (IsPrime(i)) {
			prime[i] = true;
		}
	}
	which[0] = which[1] = 1;
	Solve(N);
	cout << (which[N] ? "Win" : "Lose") << endl;
}
0