結果

問題 No.458 異なる素数の和
ユーザー h_nosonh_noson
提出日時 2017-01-26 12:14:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 86,664 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 23:53:26
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int dp[2][20001];

vector<int> get_primes(int n) {
    vector<int> ret;
    vector<bool> prime(n+1,true);
    for (int i = 2; i * i <= n; i++) if (prime[i]) {
        for (int j = 2 * i; j <= n; j+=i)
            prime[j] = false;
    }
    int i;
    REP (i,2,n) if (prime[i]) ret.push_back(i);
    return ret;
}

int main(void) {
    int i, j, n;
    cin >> n;
    REP (i,2) REP (j,0,n) dp[i][j] = -1;
    dp[0][0] = 0;
    vector<int> p = get_primes(n);
    int ans = -1;
    REP (i,p.size()) REP (j,0,n) {
        dp[(i+1)%2][j] = max(dp[i%2][j],j >= p[i] && dp[i%2][j-p[i]] >= 0 ? dp[i%2][j-p[i]]+1 : -1);
        ans = max(ans,dp[i%2][n]);
    }
    cout << ans << endl;
    return 0;
}
0