結果

問題 No.458 異なる素数の和
ユーザー tancahn2380tancahn2380
提出日時 2017-09-21 18:51:35
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,183 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 89,452 KB
実行使用メモリ 183,236 KB
最終ジャッジ日時 2024-04-26 06:35:11
合計ジャッジ時間 4,098 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
183,120 KB
testcase_01 AC 88 ms
183,140 KB
testcase_02 AC 93 ms
183,204 KB
testcase_03 AC 66 ms
182,996 KB
testcase_04 AC 68 ms
183,192 KB
testcase_05 AC 121 ms
183,236 KB
testcase_06 AC 92 ms
183,068 KB
testcase_07 AC 56 ms
183,152 KB
testcase_08 AC 120 ms
183,084 KB
testcase_09 AC 61 ms
183,036 KB
testcase_10 AC 50 ms
183,176 KB
testcase_11 WA -
testcase_12 AC 53 ms
183,132 KB
testcase_13 AC 53 ms
183,120 KB
testcase_14 AC 53 ms
183,156 KB
testcase_15 AC 54 ms
183,196 KB
testcase_16 AC 65 ms
183,124 KB
testcase_17 AC 56 ms
183,084 KB
testcase_18 AC 56 ms
183,108 KB
testcase_19 AC 52 ms
183,108 KB
testcase_20 AC 55 ms
183,188 KB
testcase_21 AC 54 ms
183,132 KB
testcase_22 AC 53 ms
183,204 KB
testcase_23 AC 57 ms
183,020 KB
testcase_24 AC 55 ms
183,000 KB
testcase_25 AC 53 ms
183,160 KB
testcase_26 AC 52 ms
183,032 KB
testcase_27 AC 88 ms
183,140 KB
testcase_28 AC 124 ms
183,172 KB
testcase_29 AC 59 ms
183,184 KB
testcase_30 AC 83 ms
183,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 100000000000000;
const double PI = acos(-1);

int dp[2300][20000];

std::vector<int> prime;
void MakePrime(int n) {
	prime.emplace_back(2);
	for (int i = 3; i < n; i += 2) {
		bool a = false;
		for (int j = 3; j <= std::sqrt(i); j += 2) {
			if (i%j == 0) {
				a = true;
			}
		}
		if (a == false) {
			prime.emplace_back(i);
		}
	}
}

int main() {
	MakePrime(20000);
	int n;
	cin >> n;
	for (int i = 0; i < 2300; i++) {
		for (int j = 0; j < 20000; j++) {
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < prime.size(); i++) {
		for (int j = 0; j <= n; j++) {
			if (dp[i][j] == -1)continue;
			if (j + prime[i] <= n)dp[i + 1][j + prime[i]] = max(dp[i + 1][j + prime[i]], dp[i][j] + 1);
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
	}
	cout << dp[prime.size()][n] << endl;
}
0