結果

問題 No.7 プライムナンバーゲーム
ユーザー hotpepsihotpepsi
提出日時 2015-02-20 01:09:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 63,272 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:43:05
合計ジャッジ時間 1,593 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <cstring>

using namespace std;

int primes = 0;
int p[10001];
int memo[10001];

static int solve(int n) {
	int &r = memo[n];
	if (r >= 0) {
		return r;
	}
	r = 0;
	for (int i = 2; i+2 <= n; ++i) {
		if (!p[i]) {
			if (!solve(n - i)) {
				r = 1;
				break;
			}
		}
	}
	return r;
}

int main(int argc, char *argv[])
{
	for (int i = 2; i <= 10000; ++i) {
		if (!p[i]) {
			for (int j = i * 2; j <= 10000; j += i) {
				p[j] = 1;
			}
		}
	}
	memset(memo, -1, sizeof(memo));
	memo[0] = memo[1] = 0;

	string s;
	while (getline(cin, s)) {
		int N = atoi(s.c_str());
		string ans = solve(N) ? "Win" : "Lose";
		cout << ans << endl;
	}
	return 0;
}
0