結果
| 問題 |
No.458 異なる素数の和
|
| ユーザー |
femto
|
| 提出日時 | 2016-12-10 00:38:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 769 bytes |
| コンパイル時間 | 1,837 ms |
| コンパイル使用メモリ | 168,852 KB |
| 実行使用メモリ | 366,204 KB |
| 最終ジャッジ日時 | 2024-11-28 20:21:22 |
| 合計ジャッジ時間 | 29,968 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 TLE * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool isPrime(int n) {
for(int i = 2; i * i <= n; i++) {
if(n % i == 0) return false;
}
return true;
}
int dp[20010][2300];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> ps;
for(int i = 2; i <= n; i++) {
if(isPrime(i)) ps.push_back(i);
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < ps.size(); j++) {
if(dp[i][j] == -1) continue;
for(int k = j; k < ps.size(); k++) {
if(i + ps[k] > n) break;
dp[i + ps[k]][k + 1] = max(dp[i + ps[k]][k + 1], dp[i][j] + 1);
}
}
}
int ans = -1;
for(int i = 0; i < ps.size() + 1; i++) {
ans = max(ans, dp[n][i]);
}
cout << ans << endl;
}
femto