結果

問題 No.458 異なる素数の和
ユーザー gotutiyangotutiyan
提出日時 2018-02-12 00:32:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,287 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 90,320 KB
実行使用メモリ 180,224 KB
最終ジャッジ日時 2024-05-01 11:33:24
合計ジャッジ時間 8,005 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e933
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long ll;
typedef std::pair<int,int> pii;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i*i<=x;i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int main() {
    int n;cin>>n;
    vector<int> v;
    rep(i,0,20000){
        if(i%2==0)continue;
        if(isPrime(i))v.pb(i);
    }
    vector<vector<int>> dp((int)v.size()+1,vector<int>(20001,-1));
    dp[0][0]=1;
    rep(i,0,v.size()){
        rep(j,0,20001){
            if(j<v[i])dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j-v[i]]+1,dp[i][j]);
        }
    }
    if(dp[(int)v.size()][n]>0)cout<<dp[(int)v.size()][n]<<endl;
    else cout<<-1<<endl;
    
    return 0;
}
0