結果

問題 No.385 カップ麺生活
ユーザー finefine
提出日時 2016-07-03 00:21:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 1,778 ms
コンパイル使用メモリ 166,144 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 06:34:20
合計ジャッジ時間 2,301 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dp[10001] = {};
bool is_prime[10001];
vector<int> prime;

void sieve(int n) {
    fill(is_prime, is_prime + n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime.emplace_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m, n;
    cin >> m >> n;
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];
    sieve(m);
    for (int i = 0; i < n; i++) {
        for (int j = m - c[i]; j >= 0; j--) {
             dp[j] = max(dp[j], dp[j + c[i]] + 1);
        }
    }
    int ans = *max_element(dp, dp + m + 1);
    for (int i = 0; i < (int)prime.size(); i++) {
        ans += dp[prime[i]];
    }
    cout << ans << "\n";
    return 0;
}
0