結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 38 ms
6,944 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 10 ms
6,948 KB
testcase_07 AC 7 ms
6,948 KB
testcase_08 AC 3 ms
6,948 KB
testcase_09 AC 16 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 7 ms
6,948 KB
testcase_12 AC 27 ms
6,944 KB
testcase_13 AC 29 ms
6,944 KB
testcase_14 AC 39 ms
6,948 KB
testcase_15 AC 36 ms
6,944 KB
testcase_16 AC 33 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];

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;

	for (i = 2; i < num-1 && !ret; i++) {
		if (!prime[i]) {
			if (!check(num-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]) {
			for (j = 2*i; j <= 10000; j += i) {
				prime[j] = true;
			}
		}
	}

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

	return 0;
}
0