結果

問題 No.288 貯金箱の仕事
ユーザー maine_honzukimaine_honzuki
提出日時 2021-05-13 10:49:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 880 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 204,624 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-25 04:40:46
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
8,024 KB
testcase_01 AC 15 ms
8,000 KB
testcase_02 AC 11 ms
8,000 KB
testcase_03 AC 5 ms
7,960 KB
testcase_04 AC 5 ms
8,000 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

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];
    }
    vector<ll> dp(610000, (ll)1e18 + 10);
    dp[0] = 0;

    ll maine = 1;
    while (M) {
        for (int i = 0; i < N; i++) {
            for (int x = 600000; x >= 0; x--) {
                dp[x + A[i]] = min(dp[x + A[i]], dp[x] + maine);
            }
        }
        for (int i = 0; i < 300000; i++) {
            dp[i] = dp[i * 2 + M % 2ll];
        }
        fill(dp.begin() + 300000, dp.end(), (ll)1e18 + 10);
        M >>= 1;
        maine <<= 1;
    }

    cout << (dp[0] > (ll)1e18 ? -1 : dp[0]) << endl;
}
0