結果

問題 No.458 異なる素数の和
ユーザー agonybusscla191agonybusscla191
提出日時 2018-02-13 01:10:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 900 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 163,836 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-18 03:32:14
合計ジャッジ時間 5,195 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int N, dp[40030];
bool prime[20010];

int main(){
        for(int i=0;i<40030;i++){
                dp[i]=-1;
        }
        for(int i=0;i<20010;i++){
                prime[i]=true;
        }
        prime[1]=true;
        for(int i=2;i<=sqrt(20010);i++){
                if(!prime[i]){
                        continue;
                }
                for(int j=i+i;j<20010;j+=i){
                        prime[j]=false;
                }
        }
        cin>>N;
        dp[0]=0;
        for(int p=1;p<20010;p++){
                if(!prime[p]){
                        continue;
                }
                for(int i=20010;i>=0;i--){
                        if(dp[i]!=(-1)){
                                dp[i+p]=max(dp[i+p], dp[i]+1);
                        }
                }
        }
        cout<<dp[N]<<endl;
        return 0;
}
0