結果

問題 No.7 プライムナンバーゲーム
ユーザー HaarHaar
提出日時 2016-04-21 19:00:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 964 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 60,432 KB
実行使用メモリ 198,912 KB
最終ジャッジ日時 2024-04-15 03:57:48
合計ジャッジ時間 3,611 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 350 ms
198,912 KB
testcase_03 AC 20 ms
13,056 KB
testcase_04 WA -
testcase_05 AC 6 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 61 ms
36,864 KB
testcase_08 WA -
testcase_09 AC 145 ms
84,608 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 262 ms
149,376 KB
testcase_14 AC 351 ms
198,144 KB
testcase_15 AC 329 ms
187,904 KB
testcase_16 AC 304 ms
172,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

const int MAX_P = 10000;

std::vector< int > prime(MAX_P,1);
std::vector< int > table;
int N;


void eratosthenes(){
	int i = 2;
	prime[0] = 0;
	while(i <= MAX_P){
		if( prime[i - 1] == 1){
			int j = 2 * i;
			while(j <= MAX_P){
				prime[j - 1] = 0;
				j += i;
			}
		}
		++i;
	}
}

int rec(int i){
	
	if(table[i] != -1){
		return table[i];
	}else{
		std::vector< int > temp(N + 1, 0);
		int t;
		
		for(int j = 0; j < i; ++j){
			if(prime[j] == 1){
				t = rec(i - (j + 1));
				temp[t] = 1;
			}
		}
		for(int j = 0; j < N + 1; ++j){
			if(temp[j] == 0){
				table[i] = j;
				break;
			}
		}
		return table[i];
	}
}

int main(){
	eratosthenes();
	
	
	std::cin >> N;
	
	table.resize(N + 1);
	
	table[0] = table[1] = 0;
	
	for(int i = 2; i < N + 1; ++i){
		table[i] = -1;
	}
	
	rec(N);
	
	if(table[N] == 1 || table[N] == 0){
		std::cout << "Lose" << std::endl;
	}else{
		std::cout << "Win" << std::endl;
	}
	
	return 0;
}
0