結果

問題 No.7 プライムナンバーゲーム
ユーザー OnjuOnju
提出日時 2015-02-08 20:56:46
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 813 bytes
コンパイル時間 397 ms
コンパイル使用メモリ 59,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 11:11:59
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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:9:7: warning: address of local variable ‘list’ returned [-Wreturn-local-addr]
  bool list[N_MAX + 1];
       ^~~~

ソースコード

diff #

#include <iostream>
#include <cmath>
#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()
{
	auto prime = calcPrime();
	int ans[N_MAX + 1];
	int N;

	cin >> N;

	memset(ans, 0, sizeof(int)*(N_MAX + 1));
	ans[0] = ans[1] = 1;

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

		if (ans[i] == 0)
			ans[i] = -1;
	}

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

	return 0;
}
0