結果
問題 | No.458 異なる素数の和 |
ユーザー |
![]() |
提出日時 | 2016-12-09 00:29:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 525 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 58,552 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 05:37:34 |
合計ジャッジ時間 | 1,743 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <iostream> #include <sstream> #include <algorithm> #include <cstring> using namespace std; int main(int argc, char *argv[]) { int f[20001] = {}; int memo[20001]; memset(memo, -1, sizeof(memo)); memo[0] = 0; for (int i = 2; i <= 20000; ++i) { if (!f[i]) { for (int j = i * 2; j <= 20000; j += i) { f[j] = 1; } for (int j = 20000; j >= i; --j) { if (memo[j - i] >= 0) { memo[j] = max(memo[j], memo[j - i] + 1); } } } } int n; cin >> n; cout << memo[n] << endl; return 0; }