結果

問題 No.288 貯金箱の仕事
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-13 11:21:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 2,441 ms
コンパイル使用メモリ 204,388 KB
実行使用メモリ 5,664 KB
最終ジャッジ日時 2023-10-25 05:27:31
合計ジャッジ時間 7,093 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
5,664 KB
testcase_01 AC 4 ms
5,664 KB
testcase_02 AC 5 ms
5,664 KB
testcase_03 AC 4 ms
5,612 KB
testcase_04 AC 5 ms
5,664 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 21 ms
5,664 KB
testcase_08 AC 9 ms
5,664 KB
testcase_09 AC 17 ms
5,664 KB
testcase_10 AC 18 ms
5,664 KB
testcase_11 AC 10 ms
5,664 KB
testcase_12 AC 17 ms
5,664 KB
testcase_13 AC 14 ms
5,664 KB
testcase_14 AC 17 ms
5,664 KB
testcase_15 AC 20 ms
5,664 KB
testcase_16 AC 18 ms
5,664 KB
testcase_17 AC 14 ms
5,664 KB
testcase_18 AC 11 ms
5,664 KB
testcase_19 AC 13 ms
5,664 KB
testcase_20 AC 9 ms
5,664 KB
testcase_21 AC 11 ms
5,664 KB
testcase_22 AC 17 ms
5,664 KB
testcase_23 AC 170 ms
5,664 KB
testcase_24 AC 87 ms
5,664 KB
testcase_25 AC 4 ms
5,664 KB
testcase_26 AC 4 ms
5,664 KB
testcase_27 AC 4 ms
5,664 KB
testcase_28 AC 4 ms
5,664 KB
testcase_29 AC 4 ms
5,664 KB
testcase_30 AC 47 ms
5,664 KB
testcase_31 AC 46 ms
5,664 KB
testcase_32 AC 89 ms
5,664 KB
testcase_33 AC 88 ms
5,664 KB
testcase_34 AC 130 ms
5,664 KB
testcase_35 AC 129 ms
5,664 KB
testcase_36 AC 170 ms
5,664 KB
testcase_37 AC 51 ms
5,664 KB
testcase_38 AC 120 ms
5,664 KB
testcase_39 AC 59 ms
5,664 KB
testcase_40 AC 61 ms
5,664 KB
testcase_41 AC 163 ms
5,664 KB
testcase_42 AC 143 ms
5,664 KB
testcase_43 AC 101 ms
5,664 KB
testcase_44 AC 72 ms
5,664 KB
testcase_45 AC 131 ms
5,664 KB
testcase_46 AC 144 ms
5,664 KB
testcase_47 AC 96 ms
5,664 KB
testcase_48 AC 105 ms
5,664 KB
testcase_49 AC 65 ms
5,664 KB
testcase_50 AC 83 ms
5,664 KB
testcase_51 AC 61 ms
5,664 KB
testcase_52 AC 86 ms
5,664 KB
testcase_53 AC 112 ms
5,664 KB
testcase_54 AC 78 ms
5,664 KB
testcase_55 AC 5 ms
5,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://ncode.syosetu.com/n4830bu/288/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N), K(N);
    for (auto&& a : A) {
        cin >> a;
    }
    for (auto&& k : K) {
        cin >> k;
    }
    M *= -1;
    for (int i = 0; i < N; i++) {
        M += A[i] * K[i];
    }

    ll maine = 3e18;
    if (M >= 0) {
        vector<ll> dp(300000, (ll)3e18);
        dp[0] = 0;
        for (int i = 0; i < N; i++) {
            for (int x = 0; x <= 290000; x++) {
                dp[x + A[i]] = min(dp[x + A[i]], dp[x] + 1ll);
            }
        }
        for (int i = M % A.back(); i < 290000; i += A.back()) {
            if (i > M)
                break;
            maine = min(maine, dp[i] + (M - i) / A.back());
        }
    }

    cout << (maine > (ll)(2e18) ? -1 : maine) << endl;
}
0