結果
| 問題 |
No.458 異なる素数の和
|
| ユーザー |
|
| 提出日時 | 2024-11-28 10:14:46 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 828 bytes |
| コンパイル時間 | 2,855 ms |
| コンパイル使用メモリ | 249,200 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 10:14:51 |
| 合計ジャッジ時間 | 4,373 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif
#include <atcoder/internal_math>
void solve() {
int N;
cin >> N;
vector<int> P;
P.reserve(3000);
const int M = 20000;
for (int i = 1; i <= min(M, N); i++)
if (atcoder::internal::is_prime_constexpr(i)) P.push_back(i);
vector<int> dp(N + 1, -1);
dp[0] = 0;
for (unsigned i{}; i < P.size(); i++) {
for (int j = N + 1; j >= 0; j--)
if (j - P[i] >= 0 && dp[j - P[i]] != -1) {
dp[j] = max(dp[j], dp[j - P[i]] + 1);
}
}
cout << dp[N] << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// std::cin >> tt;
while (tt--) {
solve();
}
}