結果

問題 No.7 プライムナンバーゲーム
ユーザー mannshi222mannshi222
提出日時 2022-04-28 21:51:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,112 bytes
コンパイル時間 919 ms
コンパイル使用メモリ 89,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:07:40
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
//#include <stdbool>
#include <vector>
#include <cmath>

using namespace std;

#define MAXN 10000

vector<bool> dp(MAXN);

vector<int> plist(MAXN);

int psize;

void makedp(int n)
{
	dp[0] = dp[1] = true;
	dp[2] = false;

	for( int i = 3; i <= n ; i++ ) {
		dp[i] = false;
		for( int j = 0; plist[j] <= i && j < psize; j++ ) {
			if( dp[i - plist[j]] == false ) {
				dp[i] = true;
				break;
			}
		}
	}
}
bool isprime( int n )
{
	if( n == 2 || n == 1) {
		return true;
	}
	for( int i = 2; i <= sqrt(n); i+=1 ) {
		if( n % i == 0 ) {
			return false;
		}
	}
	return true;
}

void makeprime( int n ) {
	for( int i = 2; i < n; i++ ) {
		if( isprime( i ) ) {
			plist[psize++] = i;
		}
	}
}

int main()
{
	int N;
	cin >>N;
	makeprime(N);
	/*
	for( int i = 0; i < psize; i++ ) {
		cout << plist[i] << " ";
	}
	cout << endl;
	*/

	makedp(N);

	/*
	for( int i = 0; i <= N; i++ ) {
		if( dp[i] == true ) {
			cout << i << " WIN" << endl;
		}
		else {
			cout << i << " LOSE" << endl;
		}
	}
	/**/
	if( dp[N] == true ) {
		cout << "Win" << endl;
	}
	else {
		cout << "Lose" << endl;
	}

	return 0;
}
0