結果

問題 No.7 プライムナンバーゲーム
ユーザー rodearodea
提出日時 2017-12-10 22:42:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 743 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 71,372 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:24:17
合計ジャッジ時間 1,656 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 45 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 13 ms
6,948 KB
testcase_07 AC 9 ms
6,948 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 19 ms
6,944 KB
testcase_10 AC 2 ms
6,948 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 32 ms
6,948 KB
testcase_13 AC 35 ms
6,944 KB
testcase_14 AC 47 ms
6,948 KB
testcase_15 AC 44 ms
6,944 KB
testcase_16 AC 40 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int p[10000], dp[10000], i, j;

void prime(int n) //エラトステネスの篩で配列pに対して、素数の時1とする
{
	for (i = 1; i <= n; i++)
	{
		p[i] = 1;
	}

	p[1] = 0;

	for (i = 2; i <= n / 2; i++)
	{
		for (j = 2; i * j <= n; j++)
		{
			p[i * j] = 0;
		}
	}
}

int main()
{
	int n;

	cin >> n;

	prime(n);

	for (i = 0; i < 10000; i++)
	{
		dp[i] = -1;
	}

	dp[2] = 1;
	dp[3] = 1;
	dp[4] = 0;
	dp[5] = 0;

	for (int i = 6; i <= n; i++) {
		dp[i] = 1;
		for (int j = 1; j < i; j++) {
			if (p[j] != 1)continue;
			if (dp[i - j] == 1) {
				dp[i] = 0;
				break;
			}
		}
	}

	if (dp[n] == 0) //dp[n]==0と同じ
	{
		cout << "Win" << endl;
	}

	else
	{
		cout << "Lose" << endl;
	}
}
0