結果

問題 No.7 プライムナンバーゲーム
ユーザー iwashi31iwashi31
提出日時 2014-11-21 10:42:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 966 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 75,704 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:40:41
合計ジャッジ時間 1,391 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

int N;
int flag[10001];
bool prime[10001];
vector<int> primes;

bool check(int num) {
	int i;
	bool ret = false;

	if (num <= 1) return false;

	if (flag[num] == 1) return true;
	if (flag[num] == -1) return false;

	int size = primes.size();
	for (i = 0; primes[i] < num-1 && i < size && !ret; i++) {
		if (!check(num-primes[i])) ret = true;
	}

	if (ret) flag[num] = 1;
	else flag[num] = -1;

	return ret;
}

int main() {
	int i, j;

	cin >> N;

	for (i = 2; i <= 10000; i++) {
		if (!prime[i]) {
			primes.push_back(i);
			for (j = 2*i; j <= 10000; j += i) {
				prime[j] = true;
			}
		}
	}

	if (check(N)) cout << "Win" << endl;
	else cout << "Lose" << endl;

	return 0;
}
0