結果

問題 No.458 異なる素数の和
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-03-01 02:15:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 173,492 KB
実行使用メモリ 239,896 KB
最終ジャッジ日時 2023-09-02 18:28:02
合計ジャッジ時間 7,598 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
239,668 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 116 ms
239,652 KB
testcase_04 AC 119 ms
239,736 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 111 ms
239,648 KB
testcase_08 WA -
testcase_09 AC 111 ms
239,652 KB
testcase_10 AC 110 ms
239,716 KB
testcase_11 WA -
testcase_12 AC 110 ms
239,648 KB
testcase_13 AC 111 ms
239,652 KB
testcase_14 AC 110 ms
239,660 KB
testcase_15 AC 111 ms
239,664 KB
testcase_16 AC 113 ms
239,652 KB
testcase_17 AC 110 ms
239,660 KB
testcase_18 AC 110 ms
239,896 KB
testcase_19 AC 110 ms
239,812 KB
testcase_20 AC 110 ms
239,676 KB
testcase_21 AC 109 ms
239,664 KB
testcase_22 AC 111 ms
239,664 KB
testcase_23 AC 110 ms
239,648 KB
testcase_24 AC 110 ms
239,756 KB
testcase_25 AC 110 ms
239,648 KB
testcase_26 AC 110 ms
239,652 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 112 ms
239,764 KB
testcase_30 AC 127 ms
239,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




vector<int> P;
void make_primes(int n)
{
	vector<bool> primes;

	primes.resize(n + 1, true);
	primes[0] = primes[1] = false;
	rep(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++)
		primes[i * (j + 2)] = false;

	rep(i, 2, n + 1) if (primes[i]) P.push_back(i);
}
//-----------------------------------------------------------------
int dp[3010][20101];
int main() {
	int N; cin >> N;
	make_primes(N + 1);

	rep(i, 0, 3010) rep(j, 0, 20101) dp[i][j] = -1;
	dp[0][0] = 0;
	rep(i, 0, P.size()) rep(j, 0, N + 1) if(0 <= dp[i][j]){
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		dp[i + 1][j + P[i]] = max(dp[i + 1][j + P[i]], dp[i][j] + 1);
	}
	cout << dp[P.size()][N] << endl;
}
0