結果

問題 No.458 異なる素数の和
ユーザー hellohellohellohello
提出日時 2018-06-10 00:28:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 2,794 ms
コンパイル使用メモリ 66,728 KB
実行使用メモリ 255,592 KB
最終ジャッジ日時 2023-09-13 02:28:08
合計ジャッジ時間 7,065 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 204 ms
70,964 KB
testcase_02 AC 254 ms
85,812 KB
testcase_03 AC 47 ms
27,560 KB
testcase_04 WA -
testcase_05 AC 596 ms
208,456 KB
testcase_06 AC 239 ms
82,336 KB
testcase_07 AC 5 ms
6,280 KB
testcase_08 AC 623 ms
209,044 KB
testcase_09 AC 19 ms
14,648 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX_N 20001
int N;
int dp[MAX_N+10][MAX_N+10];
vector<int>sieve(int n) {
	vector<int>prime;
	vector<bool>is_prime(n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) {
			prime.push_back(i);
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return prime;
}
int main() {
	cin >> N;
	vector<int>prime=sieve(N);
	int number_of_prime = prime.size();

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j < number_of_prime; j++) {
			if (j - 1 >= 0 && i - prime[j] >= 0) {
				
					dp[i][j] = max(dp[i][j - 1], dp[i - prime[j]][j - 1] + 1);
				
				
			}
		}
	}

		

		cout << dp[N][number_of_prime - 1] << endl;
	
	return 0;
}
0