結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
109,676 KB
testcase_01 AC 98 ms
139,308 KB
testcase_02 AC 136 ms
144,252 KB
testcase_03 AC 63 ms
122,508 KB
testcase_04 AC 67 ms
124,400 KB
testcase_05 AC 153 ms
174,304 KB
testcase_06 AC 108 ms
143,100 KB
testcase_07 AC 39 ms
110,860 KB
testcase_08 AC 154 ms
175,168 KB
testcase_09 AC 49 ms
115,860 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 35 ms
108,952 KB
testcase_14 AC 34 ms
109,072 KB
testcase_15 WA -
testcase_16 AC 55 ms
118,644 KB
testcase_17 AC 35 ms
109,208 KB
testcase_18 AC 34 ms
108,972 KB
testcase_19 AC 34 ms
108,848 KB
testcase_20 AC 34 ms
109,064 KB
testcase_21 AC 34 ms
108,772 KB
testcase_22 AC 34 ms
108,952 KB
testcase_23 AC 35 ms
109,200 KB
testcase_24 AC 35 ms
109,192 KB
testcase_25 AC 34 ms
108,824 KB
testcase_26 AC 35 ms
109,112 KB
testcase_27 AC 102 ms
142,000 KB
testcase_28 AC 172 ms
180,236 KB
testcase_29 AC 43 ms
113,616 KB
testcase_30 AC 87 ms
134,536 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 < 1500; i++) {
		for (int j = 0; j < 15000; 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