結果

問題 No.7 プライムナンバーゲーム
ユーザー rodearodea
提出日時 2017-12-09 18:27:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 68,864 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 12:39:36
合計ジャッジ時間 2,244 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 28 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 73 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 115 ms
5,376 KB
testcase_13 AC 125 ms
5,376 KB
testcase_14 AC 167 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 144 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

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

void prime(int n)
{
	for (i = 0; i < n; i++)
	{
		p[i] = 1;
	}

	p[0] = 0; 

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

int prime_n(int n)
{
	if (n == 0 || n == 1)
	{
		return dp[n] = 0;
	}

	if (n == 2 || n == 3)  
	{
		return dp[n] = 1;
	}

	if (dp[n] >= 0)
	{
		return dp[n];
	}

	int b = 0, x = 0;

	prime(n);

	for (i = 0; i < n ; i++)
	{
		if (p[i] == 1)
		{
			b++;

			if (prime_n(n - i - 1) == 1)
			{
				break;
			}

			else
			{
				x++;
			}
		}
	}

	if (b == x)
	{
		return dp[n] = 1;
	}

	else
	{
		return dp[n] = 0;
	}
}

int main()
{
	int n;

	cin >> n;

	if (n == 2 || n == 3)
	{
		cout << "Lose" << endl;

		return 0;
	}

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

	if (prime_n(n) == 1)
	{
		cout << "Lose" << endl;
	}

	else
	{
		cout << "Win" << endl;
	}

}
0