結果

問題 No.7 プライムナンバーゲーム
ユーザー koyumeishikoyumeishi
提出日時 2015-01-07 23:54:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 162 ms / 5,000 ms
コード長 863 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 84,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:41:18
合計ジャッジ時間 2,749 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>

using namespace std;

int grundy(vector<int> &memo, vector<int> &p, int N){
	if(memo[N] >= 0) return memo[N];
	
	set<int> s;
	for(int i=0; i<p.size(); i++){
		if(N-p[i] < 2) break;
		s.insert( grundy(memo, p, N-p[i]) );
	}
	int ret = 0;
	while(s.count(ret) != 0){
		ret++;
	}
	memo[N] = ret;
	return ret;
}

int main(){
	int N;
	cin >> N;
	vector<bool> is_P(N+1, true);
	is_P[0] = is_P[1] = false;
	vector<int> prime;
	for(int i=2; i<=N; i++){
		if(is_P[i] == false) continue;
		prime.push_back(i);
		for(int j=i+i; j<=N; j+=i){
			is_P[j] = false;
		}
	}

	vector<int> memo(N+1, -1);
	memo[0] = memo[1] = 0;
	cout << (grundy(memo, prime, N) == 0 ? "Lose":"Win") << endl;
	return 0;
}
0