結果

問題 No.458 異なる素数の和
ユーザー aaaaaa
提出日時 2018-11-09 13:13:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,980 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 100,944 KB
実行使用メモリ 394,880 KB
最終ジャッジ日時 2024-05-01 04:12:56
合計ジャッジ時間 11,569 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
394,752 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 287 ms
394,624 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 285 ms
394,624 KB
testcase_20 AC 284 ms
394,624 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

int N;
//#define N 20000
using namespace std;

int arr[200000];
vector<int>slist;

//エラトステネスの篩
void Eratosthenes() {
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			//cout << i << endl;
			slist.push_back(i);
		}
	}
}



//素数
int main(int argc, char const *argv[]) {
	int i, j;
	//int n;
	vector<vector<int>>dp(5005, vector<int>(20005, -1));

	//Eratosthenes();

	cin >> N;

	Eratosthenes();

	//dp[0][0] = 0;
	//dp[0][slist[0]] = 1;
	//int cnt = 0;

	for (i = 0; i < slist.size(); i++) {
		//if (arr[i] > n) break;
		//cnt++;

		dp[i][slist[i]] = max(1, dp[i][slist[i]] );
		
		//for (j = 0; j <= N; j++) {
		//for (j = 0; j <= N; j++) {
		for (j = N; j >= 0; j--) {

			
			if (j >= slist[i] && ( dp[i][j - slist[i]] != -1) ) {
				//dp[i + 1][j] = max(dp[i][j] + dp[i][j - slist[i]] + 1, dp[i + 1][j] );
				//dp[i + 1][j] = max(dp[i][j] + dp[i][j - slist[i]] , dp[i + 1][j]);
				//dp[i + 1][j] = max( dp[i][j - slist[i]] + 1, dp[i + 1][j]);
				//if (j - slist[i] == slist[i]) {
				//	//dp[i + 1][j] = dp[i][j];
				//}
				//else {
				//	dp[i + 1][j] = max(dp[i][j], dp[i][j - slist[i]] );
				//}
				//if (dp[i][j - slist[i]] != -1) {
					dp[i + 1][j] = max(dp[i][j - slist[i]] + 1, dp[i][j]);
				//}
				//dp[i + 1][j] = dp[i][j] + dp[i][j - slist[i]];

			}
			else {
				if (dp[i][j] != -1) {
					dp[i + 1][j] = dp[i][j];
				}
			}

		
		}


	}

	
	cout << dp[slist.size()][N] << endl;




	getchar();
	getchar();
	return 0;
}
0