結果

問題 No.288 貯金箱の仕事
ユーザー kimiyukikimiyuki
提出日時 2016-07-19 18:24:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,821 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 54,216 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-05 20:20:57
合計ジャッジ時間 29,771 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 201 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 160 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 73 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 126 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 187 ms
4,376 KB
testcase_16 AC 166 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 84 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 77 ms
4,376 KB
testcase_22 AC 155 ms
4,376 KB
testcase_23 AC 1,821 ms
4,376 KB
testcase_24 AC 461 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 5 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 6 ms
4,384 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 484 ms
4,380 KB
testcase_31 AC 489 ms
4,376 KB
testcase_32 AC 930 ms
4,376 KB
testcase_33 AC 900 ms
4,380 KB
testcase_34 AC 1,374 ms
4,380 KB
testcase_35 AC 1,202 ms
4,380 KB
testcase_36 AC 1,585 ms
4,384 KB
testcase_37 AC 457 ms
4,380 KB
testcase_38 AC 1,095 ms
4,376 KB
testcase_39 AC 528 ms
4,380 KB
testcase_40 AC 543 ms
4,380 KB
testcase_41 AC 1,530 ms
4,380 KB
testcase_42 AC 1,365 ms
4,376 KB
testcase_43 AC 170 ms
4,380 KB
testcase_44 AC 743 ms
4,380 KB
testcase_45 AC 1,390 ms
4,380 KB
testcase_46 AC 1,465 ms
4,376 KB
testcase_47 AC 1,011 ms
4,380 KB
testcase_48 AC 1,098 ms
4,380 KB
testcase_49 AC 335 ms
4,376 KB
testcase_50 AC 877 ms
4,380 KB
testcase_51 AC 632 ms
4,376 KB
testcase_52 AC 889 ms
4,380 KB
testcase_53 AC 1,164 ms
4,380 KB
testcase_54 AC 810 ms
4,380 KB
testcase_55 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const int W = 500;
const ll infty = ll(1e18)+9;
int main() {
    int n; ll m; scanf("%d%lld", &n, &m);
    vector<int> a(n); repeat (i,n) scanf("%d",   &a[i]);
    vector<ll>  k(n); repeat (i,n) scanf("%lld", &k[i]);
    ll x = whole(inner_product, a, k.begin(), 0ll) - m;
    ll ans = infty;
    if (x >= 0) {
        int l = min<ll>(3e5, x+1); // magic
        array<ll,W+2> dp = {};
        whole(fill, dp, infty);
        dp[0] = 0;
        repeat (acc,l) {
            int i = acc % dp.size();
            if (dp[i] == infty) continue;
            repeat (j,n) {
                setmin(dp[(i + a[j]) % dp.size()], dp[i] + 1);
                if ((x - acc) % a[j] == 0) {
                    setmin(ans, dp[i] + (x - acc) / a[j]);
                }
            }
            dp[i] = infty;
        }
    }
    if (ans == infty) ans = -1;
    printf("%lld\n", ans);
    return 0;
}
0