結果

問題 No.458 異なる素数の和
ユーザー 小指が強い人小指が強い人
提出日時 2016-01-06 19:25:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 59,484 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 14:43:09
合計ジャッジ時間 1,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
4,380 KB
testcase_01 AC 8 ms
4,376 KB
testcase_02 AC 8 ms
4,376 KB
testcase_03 AC 8 ms
4,376 KB
testcase_04 AC 8 ms
4,376 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,376 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 8 ms
4,380 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 8 ms
4,380 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 9 ms
4,376 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 8 ms
4,376 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int MakePrime(vector<int>& v, int n) {
    bool p[100001] = {1, 1};
    for(int i = 2; i <= n; i++) {
        if(p[i]) continue;
        v.push_back(i);
        for(int j = i * 2; j <= n; j += i)
            p[j] = true;
    }
    return v.size();
}

int main(void)
{
    const int maxdp = 20001;
    int n;
    vector<int> v;
    int dp[maxdp] = {1};
    int pn = MakePrime(v, 1000);
    cin >> n;
    for(int i = 0; i < pn; i++) {
        for(int j = maxdp - 1; j >= 0; j--) {
            if(dp[j] >= 1) {
                if(v[i] + j >= maxdp)
                    continue;
                dp[v[i] + j] = max(dp[v[i] + j], dp[j] + 1);
            }
        }
    }
    cout << dp[n] - 1 << endl;
    return 0;
}
0