結果

問題 No.288 貯金箱の仕事
ユーザー PachicobuePachicobue
提出日時 2018-12-08 16:57:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 203,820 KB
実行使用メモリ 15,116 KB
最終ジャッジ日時 2023-10-12 05:00:08
合計ジャッジ時間 8,054 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 298 ms
15,116 KB
testcase_24 AC 79 ms
9,376 KB
testcase_25 AC 4 ms
4,352 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 3 ms
4,352 KB
testcase_30 AC 87 ms
14,872 KB
testcase_31 AC 86 ms
14,880 KB
testcase_32 AC 157 ms
14,988 KB
testcase_33 AC 157 ms
14,872 KB
testcase_34 AC 227 ms
14,928 KB
testcase_35 AC 227 ms
14,992 KB
testcase_36 AC 298 ms
14,872 KB
testcase_37 AC 92 ms
7,484 KB
testcase_38 AC 206 ms
14,708 KB
testcase_39 AC 106 ms
6,756 KB
testcase_40 AC 110 ms
14,880 KB
testcase_41 AC 286 ms
14,920 KB
testcase_42 AC 249 ms
14,984 KB
testcase_43 AC 37 ms
6,212 KB
testcase_44 AC 54 ms
7,824 KB
testcase_45 AC 162 ms
11,492 KB
testcase_46 AC 252 ms
14,924 KB
testcase_47 AC 130 ms
7,744 KB
testcase_48 AC 178 ms
14,344 KB
testcase_49 AC 71 ms
10,408 KB
testcase_50 AC 113 ms
7,804 KB
testcase_51 AC 77 ms
11,320 KB
testcase_52 AC 142 ms
14,196 KB
testcase_53 AC 181 ms
14,092 KB
testcase_54 AC 105 ms
11,972 KB
testcase_55 AC 2 ms
4,352 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 + 1) / 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