結果

問題 No.458 異なる素数の和
ユーザー 波多野充波多野充
提出日時 2021-10-21 13:03:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,785 bytes
コンパイル時間 4,604 ms
コンパイル使用メモリ 263,956 KB
実行使用メモリ 814,744 KB
最終ジャッジ日時 2023-10-21 07:08:15
合計ジャッジ時間 8,542 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,348 KB
testcase_01 AC 497 ms
412,748 KB
testcase_02 MLE -
testcase_03 AC 102 ms
84,068 KB
testcase_04 AC 136 ms
110,732 KB
testcase_05 MLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define reps(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define sortu(a) sort(a.begin(), a.end())
#define sortd(a) sort(a.rbegin(), a.rend())
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define spaced(a) do {cout << a[0]; for (int _ = 1; _ < a.size(); _++) cout << " " << a[_]; cout << endl;} while (0)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
using vi = vector<int>;
using ll = long long;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vs = vector<string>;
using pii = pair<int, int>;
using mint = modint1000000007;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}

int main() {
    int n; cin >> n;
    vector<bool> isPrime(n + 1, true); isPrime[0] = isPrime[1] = false;
    reps(i, 2, n) {
        if (!isPrime[i]) continue;
        for (int j = 2 * i; j <= n; j+= i) {
            isPrime[j] = false;
        }
    }
    vvi dp(n + 1, vi(n + 1));
    reps(i, 2, n + 1) {
        if (isPrime[i]) dp[i][i] = 1;
        reps(j, 2, n + 1) {
            chmax(dp[i][j], dp[i - 1][j]);
            if (isPrime[i] && i <= j && dp[i - 1][j - i] > 0) {
                chmax(dp[i][j], dp[i - 1][j - i] + 1);
            }
        }
    }
    if (dp[n][n] > 0) cout << dp[n][n] << endl;
    else cout << -1 << endl;
    return 0;
}
0