結果

問題 No.458 異なる素数の和
ユーザー eQeeQe
提出日時 2019-01-14 21:06:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 581 ms
コンパイル使用メモリ 75,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 05:47:02
合計ジャッジ時間 1,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

vector<ll> primes;

void eratos(ll N) {
    ll isp[N+5];
    memset(isp, 1, sizeof(isp));
    isp[0]=isp[1]=0;
    ll i, j;
    
    for(i=2; i*i<=N; i++) {
        if(isp[i]==0) continue;
        for(j=i+i; j<=N; j+=i)
            isp[j]=0;
    }
    
    for(i=0; i<=N; i++)
        if(isp[i]) primes.push_back(i);
}

int main(void) {
    ll M;
    cin >> M;
    ll i, j;
    ll dp[20202];
    memset(dp, -1, sizeof(dp));
    
    eratos(M);
    
    dp[0]=0;
    for(i=0; i<primes.size(); i++)
        for(j=M-primes[i]; j>=0; j--)
            if(dp[j]!=-1) dp[j+primes[i]]=max(dp[j+primes[i]], dp[j]+1);
   
    pt(dp[M]);
}

0