結果
| 問題 | No.458 異なる素数の和 |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-05-18 17:43:07 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 1,395 bytes |
| 記録 | |
| コンパイル時間 | 6,238 ms |
| コンパイル使用メモリ | 151,680 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-25 02:02:47 |
| 合計ジャッジ時間 | 7,552 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp:21:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
21 | bool checked[MAX_N + 1];
| ^~~~~~~~~
main.cpp:21:18: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
main.cpp:69:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
69 | int dp[N + 1];
| ^~~~~
main.cpp:69:10: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:66:7: note: declared here
66 | int N;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
class Prime {
public:
vector<ll> prime_list;
const ll MAX_N = 100000;
Prime() {
bool checked[MAX_N + 1];
memset(checked, false, sizeof(checked));
for (ll i = 2; i <= MAX_N; ++i) {
if (!checked[i]) {
prime_list.push_back(i);
for (ll j = i * i; j <= MAX_N; j += i) {
checked[j] = true;
}
}
}
}
map<ll, int> prime_division(ll n) {
map<ll, int> res;
for (ll i = 0; prime_list[i] <= sqrt(n); ++i) {
ll p = prime_list[i];
while (n % p == 0) {
++res[p];
n /= p;
}
}
if (n != 1) {
res[n] = 1;
}
return res;
}
bool is_prime(ll n) {
if (n <= 1) return false;
for (int i = 0; i < prime_list.size(); ++i) {
if (n % prime_list[i]) return false;
}
return true;
}
};
int main() {
int N;
Prime prime;
cin >> N;
int dp[N + 1];
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (ll v : prime.prime_list) {
if (v > N) break;
for (int i = N - v; i >= 0; --i) {
if (dp[i] == -1) continue;
dp[i + v] = max(dp[i + v], dp[i] + 1);
}
}
cout << dp[N] << endl;
return 0;
}
siman