結果

問題 No.288 貯金箱の仕事
ユーザー kimiyukikimiyuki
提出日時 2016-07-19 18:24:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,890 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 456 ms
コンパイル使用メモリ 56,024 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:53:09
合計ジャッジ時間 30,792 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 208 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 166 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 76 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 130 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 193 ms
5,376 KB
testcase_16 AC 170 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 86 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 79 ms
5,376 KB
testcase_22 AC 160 ms
5,376 KB
testcase_23 AC 1,890 ms
5,376 KB
testcase_24 AC 480 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 6 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 500 ms
5,376 KB
testcase_31 AC 500 ms
5,376 KB
testcase_32 AC 970 ms
5,376 KB
testcase_33 AC 966 ms
5,376 KB
testcase_34 AC 1,432 ms
5,376 KB
testcase_35 AC 1,432 ms
5,376 KB
testcase_36 AC 1,886 ms
5,376 KB
testcase_37 AC 536 ms
5,376 KB
testcase_38 AC 1,305 ms
5,376 KB
testcase_39 AC 628 ms
5,376 KB
testcase_40 AC 648 ms
5,376 KB
testcase_41 AC 1,805 ms
5,376 KB
testcase_42 AC 1,566 ms
5,376 KB
testcase_43 AC 180 ms
5,376 KB
testcase_44 AC 780 ms
5,376 KB
testcase_45 AC 1,455 ms
5,376 KB
testcase_46 AC 1,588 ms
5,376 KB
testcase_47 AC 1,055 ms
5,376 KB
testcase_48 AC 1,151 ms
5,376 KB
testcase_49 AC 351 ms
5,376 KB
testcase_50 AC 915 ms
5,376 KB
testcase_51 AC 660 ms
5,376 KB
testcase_52 AC 940 ms
5,376 KB
testcase_53 AC 1,221 ms
5,376 KB
testcase_54 AC 851 ms
5,376 KB
testcase_55 AC 1 ms
5,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