結果

問題 No.7 プライムナンバーゲーム
ユーザー tempura-samatempura-sama
提出日時 2016-04-18 12:19:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 588 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 56,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:57:42
合計ジャッジ時間 1,207 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;

#define N 10000

int n;
int p[N+1];
int dpm[N+1];

void pf()
{
	int k = 0;
	for ( int i = 2; i <= n; i++ ) {
		if ( p[i] != 0 ) { continue; }
		for ( int j = i; j < n; j += i ) {
			p[j] = 1;
		}
		p[k++] = i;
	}
	p[k] = 0;
}

int dp()
{
	for ( int i = 2; i <= n; i++ ) {
		for ( int j = 0; p[j] != 0 && p[j] < i; j++ ) {
			int x = i - p[j];
			if ( x > 1 && dpm[x] == 0 ) {
				dpm[i] = 1;
				break;
			}
		}
	}
	return 0;
}

int main()
{
	cin >> n;

	pf();
	dp();

	cout << (dpm[n] ? "Win" : "Lose") << endl;

	return 0;
}
0