結果
問題 | No.458 異なる素数の和 |
ユーザー |
![]() |
提出日時 | 2019-04-16 10:54:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 854 bytes |
コンパイル時間 | 681 ms |
コンパイル使用メモリ | 77,060 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 08:11:01 |
合計ジャッジ時間 | 1,951 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | WA * 1 RE * 27 |
ソースコード
#include <vector> #include <iostream> #include <cmath> using namespace std; vector<int> sieve(int n) { vector<int> primes; vector<bool> is_composite(n + 1, false); for (int num = 2; num <= n; num++) { if (!is_composite[num]) { primes.push_back(num); for (int i = 2; i * num <= n; i++) is_composite[i * num] = true; } } return move(primes); } // dp[i] = iを素数の和で表現するとき, 素数の数の最大値 int main() { int N; cin >> N; vector<int> dp(N + 1, -1); vector<int> primes = sieve(N); for (int prime : primes) { for (int num = 0; num <= N; num++) { int updated = num + prime; if (updated < N + 1) { dp[updated] = max(dp[updated], dp[num] + 1); } } } return dp[N]; }