結果

問題 No.458 異なる素数の和
ユーザー tlllunetlllune
提出日時 2018-11-10 16:31:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 851 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 77,068 KB
実行使用メモリ 81,988 KB
最終ジャッジ日時 2023-08-16 04:05:09
合計ジャッジ時間 3,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
81,884 KB
testcase_01 AC 50 ms
81,776 KB
testcase_02 AC 50 ms
81,780 KB
testcase_03 AC 51 ms
81,848 KB
testcase_04 AC 50 ms
81,800 KB
testcase_05 AC 50 ms
81,728 KB
testcase_06 AC 51 ms
81,828 KB
testcase_07 AC 51 ms
81,784 KB
testcase_08 AC 51 ms
81,780 KB
testcase_09 AC 50 ms
81,776 KB
testcase_10 AC 51 ms
81,776 KB
testcase_11 AC 50 ms
81,776 KB
testcase_12 AC 51 ms
81,788 KB
testcase_13 AC 52 ms
81,920 KB
testcase_14 AC 52 ms
81,988 KB
testcase_15 AC 52 ms
81,792 KB
testcase_16 AC 51 ms
81,724 KB
testcase_17 AC 51 ms
81,780 KB
testcase_18 AC 52 ms
81,848 KB
testcase_19 AC 51 ms
81,780 KB
testcase_20 AC 51 ms
81,904 KB
testcase_21 AC 52 ms
81,852 KB
testcase_22 AC 51 ms
81,908 KB
testcase_23 AC 51 ms
81,904 KB
testcase_24 AC 51 ms
81,840 KB
testcase_25 AC 51 ms
81,788 KB
testcase_26 AC 51 ms
81,788 KB
testcase_27 AC 51 ms
81,720 KB
testcase_28 AC 51 ms
81,828 KB
testcase_29 AC 51 ms
81,796 KB
testcase_30 AC 51 ms
81,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <map>

using namespace std;

vector<int> sq;
int ssm=0,n;
int dp[1010][20010];
bool f;

int main(){
    for(int i=2;ssm<1001;i++){
        f=true;
        for(int j:sq)f=f and (i%j!=0);
        if(f){
            ssm+=1;
            sq.push_back(i);
        }
    }
    scanf("%d",&n);
    for(int i=0;i<20001;i++)dp[0][i]=0;
    for(int j=1;j<=1001;j++){
        for(int i=20000;i>=0;i--){
            dp[j][i]=dp[j-1][i];
            if((i==0 or dp[j-1][i]!=0) and sq[j-1]+i<20001)dp[j][i+sq[j-1]]=max(dp[j-1][i]+1,dp[j][i+sq[j-1]]);

        }
    }
    //for(int i=0;i<20;i++)printf("%d ",dp[92][i]);
    if(dp[1001][n]==0)dp[1001][n]=-1;
    printf("%d\n",dp[1001][n]);

}
0