結果

問題 No.458 異なる素数の和
ユーザー 8991tae8991tae
提出日時 2018-01-02 23:27:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 76,244 KB
実行使用メモリ 181,576 KB
最終ジャッジ日時 2023-08-24 16:59:20
合計ジャッジ時間 3,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,648 KB
testcase_01 AC 49 ms
100,768 KB
testcase_02 AC 54 ms
115,256 KB
testcase_03 AC 17 ms
51,204 KB
testcase_04 AC 20 ms
57,268 KB
testcase_05 AC 106 ms
167,236 KB
testcase_06 AC 51 ms
111,072 KB
testcase_07 AC 3 ms
11,776 KB
testcase_08 WA -
testcase_09 AC 9 ms
30,316 KB
testcase_10 WA -
testcase_11 AC 112 ms
181,576 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 13 ms
38,620 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 49 ms
109,060 KB
testcase_28 AC 110 ms
179,404 KB
testcase_29 AC 7 ms
22,108 KB
testcase_30 AC 36 ms
86,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;

#define N 20005
int a[N];
int dp[2300][N];
void prime(int n){
    int t=1;
    for(int i=2;i<=n;i++){
        bool flag=true;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0)flag=false;
        }
        if(flag==true){
            a[t]=i;
            t++;
        }
    }
    a[0]=t-1;/*a[0]が個数*/
}

int main(){
    int n;cin>>n;
    prime(n);
    for(int i=1;i<=a[0];i++)for(int j=0;j<=n;j++)dp[i][j]=-1;
    dp[1][2]=1;
    for(int i=2;i<=a[0];i++){
        for(int j=0;j<=n;j++){
            if(j<a[i])dp[i][j]=dp[i-1][j];
            else if(dp[i-1][j]!=-1&&dp[i-1][j-a[i]]!=-1){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i]]+1);
            }else if(dp[i-1][j]!=-1){
                dp[i][j]=dp[i-1][j];
            }else if(dp[i-1][j-a[i]]!=-1){
                dp[i][j]=dp[i-1][j-a[i]]+1;
            }else{
                dp[i][j]=-1;
            }
        }
    }
    cout<<dp[a[0]][n]<<endl;
    
    return 0;
}

0