結果

問題 No.458 異なる素数の和
ユーザー eQeeQe
提出日時 2019-01-14 20:59:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,268 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 75,432 KB
実行使用メモリ 4,568 KB
最終ジャッジ日時 2023-09-05 05:37:59
合計ジャッジ時間 1,965 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
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 <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[20202];
    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));
    
    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