結果

問題 No.7 プライムナンバーゲーム
ユーザー OnjuOnju
提出日時 2015-02-08 18:52:48
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 893 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 61,292 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 11:06:50
合計ジャッジ時間 3,375 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool* calcPrime()’:
main.cpp:11:7: warning: address of local variable ‘list’ returned [-Wreturn-local-addr]
  bool list[N_MAX + 1];
       ^~~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <cstring>
#define N_MAX 10000
using namespace std;

bool* calcPrime()
{
	bool list[N_MAX + 1];
	int sqrtnmax = sqrt(N_MAX);

	for (int i = 2; i <= N_MAX; ++i)
		list[i] = true;

	for (int i = 2; i <= sqrtnmax; ++i)
	{
		if (list[i])
		{
			int jmax = N_MAX / i;
			for (int j = i; j <= jmax; ++j)
				list[i*j] = false;
		}
	}

	return list;
}

int main()
{
	enum ANS
	{
		NONE,
		WIN,
		LOSE
	};
	auto prime = calcPrime();
	ANS ans[N_MAX];
	int N;

	cin >> N;

	memset(ans, NONE, sizeof(ANS)*N_MAX);
	ans[0] = ans[1] = WIN;

	for (int i = 2; i <= N; ++i)
	{
		for (int j = 2; j < i; ++j)
		{
			if (prime[j] && ans[i - j] == LOSE)
			{
				ans[i] = WIN;
				break;
			}
		}

		if (ans[i] == NONE)
			ans[i] = LOSE;
	}

	if (ans[N] == WIN)
		cout << "Win" << endl;
	else
		cout << "Lose" << endl;

	return 0;
}
0