結果

問題 No.385 カップ麺生活
ユーザー yosupotyosupot
提出日時 2016-07-01 23:02:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 62,980 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-27 20:47:06
合計ジャッジ時間 1,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (!n) ? 1 : 10 * TEN(n-1); }

int m, n, c[20];

int dp0[10100], dp1[10100];
bool us0[10100], us1[10100];
int dfs(int x) {
    if (x < 0) return -100000;
    if (x == 0) return 0;
    if (us0[x]) return dp0[x];
    us0[x] = true;
    int ans = -100000;
    for (int i = 0; i < n; i++) {
        ans = max(ans, 1+dfs(x-c[i]));
    }
    return dp0[x] = ans;
}

int dfs2(int x) {
    if (x < 0) return -100000;
    if (x == 0) return 0;
    if (us1[x]) return dp1[x];
    us1[x] = true;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, 1+dfs2(x-c[i]));
    }
    return dp1[x] = ans;
}

int main() {
    cin >> m;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    int ans = dfs2(m);
    for (int i = 2; i < m; i++) {
        bool f = true;
        for (int j = 2; j*j <= i; j++) {
            if (i % j == 0) f = false;
        }
        if (f) {
            ans += max(0, dfs(m-i));
        }
    }
    cout << ans << endl;
    return 0;
}
0