結果

問題 No.458 異なる素数の和
ユーザー pin
提出日時 2017-11-14 18:57:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
MLE  
実行時間 -
コード長 1,038 bytes
コンパイル時間 723 ms
コンパイル使用メモリ 73,220 KB
実行使用メモリ 785,020 KB
最終ジャッジ日時 2024-11-25 02:10:27
合計ジャッジ時間 13,541 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 3
other MLE * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

const int INF = 100000;
int prime[10000];
int dp[10000][20005];
bool is_prime[100000];

int func(int n){
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++){
        if (is_prime[i]){
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;

        }
    }

    return p;

}

int main(void){
    int n;
    cin >> n;

    int s = func(n);
    memset(dp, -1,sizeof(dp));
    dp[0][0] = 0;


    for (int i = 0; i < s; i++){
        for (int j = 0; j <= n; j++){
            dp[i + 1][j] = dp[i][j];
            if (prime[i] <= j&&dp[i][j - prime[i]] != -1){
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - prime[i]] + 1);
            }
        }
    }

    cout << dp[s][n] << endl;

}
0