結果

問題 No.288 貯金箱の仕事
ユーザー kimiyukikimiyuki
提出日時 2016-07-19 18:21:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,247 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 55,892 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 16:52:14
合計ジャッジ時間 6,807 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 312 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 247 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 114 ms
6,944 KB
testcase_12 AC 4 ms
6,940 KB
testcase_13 AC 191 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 284 ms
6,940 KB
testcase_16 AC 251 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 127 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 117 ms
6,944 KB
testcase_22 AC 236 ms
6,940 KB
testcase_23 TLE -
testcase_24 AC 725 ms
6,944 KB
testcase_25 AC 5 ms
6,944 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 4 ms
6,948 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 11 ms
6,944 KB
testcase_30 AC 733 ms
6,944 KB
testcase_31 AC 746 ms
6,944 KB
testcase_32 AC 1,427 ms
6,940 KB
testcase_33 AC 1,457 ms
6,944 KB
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 AC 562 ms
6,944 KB
testcase_38 AC 1,946 ms
6,948 KB
testcase_39 AC 930 ms
6,944 KB
testcase_40 AC 873 ms
6,944 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 AC 161 ms
6,944 KB
testcase_44 AC 1,162 ms
6,944 KB
testcase_45 AC 1,520 ms
6,944 KB
testcase_46 TLE -
testcase_47 AC 1,552 ms
6,944 KB
testcase_48 AC 1,700 ms
6,940 KB
testcase_49 AC 311 ms
6,940 KB
testcase_50 AC 1,364 ms
6,948 KB
testcase_51 AC 676 ms
6,944 KB
testcase_52 AC 1,089 ms
6,944 KB
testcase_53 AC 1,814 ms
6,944 KB
testcase_54 AC 1,255 ms
6,944 KB
testcase_55 AC 2 ms
6,944 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>(5e5, 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