結果

問題 No.458 異なる素数の和
ユーザー gotutiyangotutiyan
提出日時 2018-02-12 09:59:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,265 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 90,196 KB
実行使用メモリ 180,352 KB
最終ジャッジ日時 2024-05-03 06:58:01
合計ジャッジ時間 6,805 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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,1,20001){
        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]=0;
    rep(i,0,v.size()){
        rep(j,0,n+1){
            dp[i+1][j]=dp[i][j];
            
            if(j>=v[i]&&dp[i][j-v[i]]!=-1) dp[i+1][j]=max(dp[i][j-v[i]]+1,dp[i+1][j]);
        }
    }
    cout<<dp[(int)v.size()][n]<<endl;
    
    return 0;
}
0