結果

問題 No.458 異なる素数の和
ユーザー tactac
提出日時 2019-05-03 20:42:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 103,456 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 05:52:18
合計ジャッジ時間 3,817 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<climits>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

const int lim = 20001;
int table[lim];
vector<int> v;
void prime() {
    rep(i, lim) if (i % 2 == 0) table[i] = 1;
    table[2] = 0;
    table[1] = 1;
    for (int i = 3; i < sqrt(lim) + 1; i += 2) {
        int key = 2 * i;
        while (key < lim) {
            table[key] = 1;
            key += i;
        }
    }
    rep(i, lim) if (table[i] == 0) v.push_back(i);
}
int main() {
    prime();
    int n; cin >> n;
    int dp[lim];
    rep(i, lim) dp[i] = -1;
    dp[0] = 0;
    rep(k, v.size()) {
        for (int i = lim - 1; i >= 0; --i) {
            if (dp[i] != -1 && i + v[k] < lim) {
                chmax(dp[i + v[k]], dp[i] + 1);
            }
        }
    }
    cout << dp[n] << endl;
}

0