結果

問題 No.458 異なる素数の和
ユーザー KhiromuKhiromu
提出日時 2017-03-17 18:24:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 783 bytes
コンパイル時間 858 ms
コンパイル使用メモリ 77,612 KB
実行使用メモリ 181,044 KB
最終ジャッジ日時 2023-09-17 19:22:57
合計ジャッジ時間 4,124 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
180,552 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 60 ms
180,736 KB
testcase_04 AC 62 ms
180,772 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 53 ms
180,608 KB
testcase_08 WA -
testcase_09 AC 55 ms
180,656 KB
testcase_10 AC 53 ms
180,656 KB
testcase_11 WA -
testcase_12 AC 55 ms
180,604 KB
testcase_13 WA -
testcase_14 AC 47 ms
180,696 KB
testcase_15 AC 46 ms
180,844 KB
testcase_16 AC 48 ms
180,692 KB
testcase_17 AC 45 ms
180,560 KB
testcase_18 AC 46 ms
180,756 KB
testcase_19 AC 45 ms
180,616 KB
testcase_20 AC 45 ms
180,608 KB
testcase_21 AC 46 ms
180,580 KB
testcase_22 AC 45 ms
180,856 KB
testcase_23 AC 46 ms
180,660 KB
testcase_24 AC 46 ms
180,704 KB
testcase_25 AC 46 ms
180,748 KB
testcase_26 AC 46 ms
180,584 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 49 ms
180,652 KB
testcase_30 AC 63 ms
180,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

vector<int> prime;
void crate_prime(int n) {
	vector<bool> p;
	p.resize(n + 1, true);
	p[0] = p[1] = false;
	for (int i = 2; i*i <= n; i++) {
		if (p[i]) {
			for (int j = 2 * i; j < n; j += i) p[j] = false;
		}
	}

	REP(i, 2, n) if (p[i]) prime.push_back(i);
}

int dp[2270][20001];
int main()
{
	int N;
	cin >> N;

	crate_prime(N);
	REP(i, 0, 2270) REP(j, 0, 20001) dp[i][j] = -1;

	dp[0][0] = 0;
	REP(i, 0, prime.size()) {
		REP(j, 0, N + 1) {
			if (dp[i][j] >= 0) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
				dp[i + 1][j + prime[i]] = max(dp[i + 1][j + prime[i]], dp[i][j] + 1);
			}
		}
	}

	cout << dp[(int)prime.size()][N] << endl;
	return 0;
}
0