結果

問題 No.7 プライムナンバーゲーム
ユーザー kurenai3110kurenai3110
提出日時 2016-09-14 12:39:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 261 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 64,528 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:02:40
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <set>
using namespace std;
int N;

bool so[10001];
int mem[10001];

int grundy(int n) {
	if (mem[n] != -1)return mem[n];

	set<int> s;
	for (int i = 2; i <= n; i++) {
		if (!so[i] && n - i > 1) s.insert(grundy(n - i));
	}
	int res = 0;
	while (s.count(res)) res++;
	return mem[n] = res;
}

int main()
{
	cin >> N;

	for (int i = 2; i <= 10000; i++) {
		if (!so[i]) {
			for (int j = i * 2; j <= 10000; j += i) so[j] = true;
		}
	}
	for (int i = 0; i < 10001; i++) mem[i] = -1;

	if (grundy(N)) {
		cout << "Win" << endl;
	}
	else {
		cout << "Lose" << endl;
	}

	return 0;
}
0