結果

問題 No.288 貯金箱の仕事
ユーザー kimiyukikimiyuki
提出日時 2016-07-19 18:17:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,423 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 72,276 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-23 16:51:12
合計ジャッジ時間 8,673 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 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 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 616 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 487 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 230 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 402 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 577 ms
5,376 KB
testcase_16 AC 499 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 263 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 244 ms
5,376 KB
testcase_22 AC 486 ms
5,376 KB
testcase_23 TLE -
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 #

#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#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 int infty = 1e9+7;
const ll inftyll = 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 = inftyll;
    if (x >= 0) {
        int l = min<ll>(1e6, x);
        array<int,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 == inftyll) ans = -1;
    printf("%lld\n", ans);
    return 0;
}
0