結果

問題 No.288 貯金箱の仕事
ユーザー PachicobuePachicobue
提出日時 2018-12-08 17:00:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 203,392 KB
実行使用メモリ 15,212 KB
最終ジャッジ日時 2023-10-12 05:00:40
合計ジャッジ時間 7,987 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 311 ms
14,900 KB
testcase_24 AC 83 ms
9,328 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 89 ms
14,956 KB
testcase_31 AC 89 ms
14,880 KB
testcase_32 AC 163 ms
14,980 KB
testcase_33 AC 163 ms
15,212 KB
testcase_34 AC 237 ms
14,972 KB
testcase_35 AC 237 ms
14,912 KB
testcase_36 AC 312 ms
15,024 KB
testcase_37 AC 92 ms
7,468 KB
testcase_38 AC 215 ms
14,952 KB
testcase_39 AC 107 ms
6,812 KB
testcase_40 AC 114 ms
15,024 KB
testcase_41 AC 298 ms
15,184 KB
testcase_42 AC 260 ms
14,972 KB
testcase_43 AC 38 ms
6,284 KB
testcase_44 AC 56 ms
7,820 KB
testcase_45 AC 169 ms
11,660 KB
testcase_46 AC 263 ms
15,024 KB
testcase_47 AC 131 ms
7,868 KB
testcase_48 AC 184 ms
14,468 KB
testcase_49 AC 74 ms
10,172 KB
testcase_50 AC 115 ms
7,728 KB
testcase_51 AC 80 ms
11,332 KB
testcase_52 AC 150 ms
14,176 KB
testcase_53 AC 192 ms
14,204 KB
testcase_54 AC 110 ms
12,128 KB
testcase_55 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
int main()
{
    int N;
    ll M;
    std::cin >> N >> M;
    std::vector<int> A(N);
    std::vector<ll> K(N);
    for (int i = 0; i < N; i++) { std::cin >> A[i]; }
    int max = 0;
    for (int i = 0; i < N; i++) { std::cin >> K[i], M -= K[i] * A[i], max = std::max(max, A[i]); }
    M = -M;
    ll ans = (std::max(0LL, M - max * max + max) / max);
    M -= ans * max;
    std::vector<int> memo(max * max, max * max);
    auto dp = [&](auto&& self, const ll M) -> int {
        if (M == 0) { return 0; }
        if (M < 0) { return max * max; }
        if (memo[M] != max * max) { return memo[M]; }
        int ans = max * max;
        for (const ll a : A) { ans = std::min(ans, self(self, M - a)); }
        return memo[M] = ans + 1;
    };
    const int add = dp(dp, M);
    if (add >= max * max) { return std::cout << -1 << std::endl, 0; }
    std::cout << ans + add << std::endl;
    return 0;
}
0