結果
問題 | No.458 異なる素数の和 |
ユーザー |
![]() |
提出日時 | 2018-01-10 15:11:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 1,013 bytes |
コンパイル時間 | 575 ms |
コンパイル使用メモリ | 77,492 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 15:37:32 |
合計ジャッジ時間 | 1,778 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <map>#include <string>#include <numeric>#define rep(i, n) for (int i = 0; i < (n); i++)using ll = long long int;using namespace std;bool isPrime[20000] = {false};int dp[20000];void eratos(int n){for (int i = 2; i <= n; i++)isPrime[i] = true;for (int i = 2; i <= n; i++){if (isPrime[i]){for (int j = 2; i * j <= n; j++){isPrime[i * j] = false;}}}return;}int main(){int N;cin >> N;eratos(N);vector<int> prime;rep(i, N + 1)dp[i] = -1;dp[0] = 0;for (int i = 2; i <= N; i++)if (isPrime[i])prime.push_back(i);for (auto x : prime){for (int i = N; i >= 0; i--){if(x + i <= N && dp[i] != -1)dp[i + x] = max(dp[i + x], dp[i] + 1);}}cout << dp[N] << endl;return 0;}