結果

問題 No.458 異なる素数の和
ユーザー recososorecososo
提出日時 2020-02-25 17:39:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 166,652 KB
実行使用メモリ 180,460 KB
最終ジャッジ日時 2024-04-21 13:47:50
合計ジャッジ時間 3,494 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 48 ms
53,680 KB
testcase_02 AC 62 ms
69,436 KB
testcase_03 AC 13 ms
14,464 KB
testcase_04 AC 15 ms
18,036 KB
testcase_05 AC 183 ms
150,600 KB
testcase_06 AC 58 ms
65,552 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 167 ms
152,024 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 213 ms
180,460 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 7 ms
9,820 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 66 ms
62,372 KB
testcase_28 AC 160 ms
176,696 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 34 ms
39,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin >> n;
    vector<int> p(n+1,true);
    p[0]=false;
    p[1]=false;
    for(int i=2;i*i<=n;i++){
        if(p[i]){
            for(int j=2;j*i<=n;j++){
                p[i*j]=false;
            }
        }
    }
    vector<int> v;
    for(int i=2;i<=n;i++){
        if(p[i]){
            v.push_back(i);
        }
    }
    int k=v.size();
    int dp[k+1][n+1];
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    for(int i=0;i<k;i++){
        for(int j=0;j<=n;j++){
            if(dp[i][j]!=-1){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
                if(j+v[i]<=n){
                    dp[i+1][j+v[i]]=max(dp[i+1][j+v[i]],dp[i][j]+1);
                }
            }
        }
    }
    cout << dp[k][n] << endl;
}
0