結果

問題 No.288 貯金箱の仕事
ユーザー parukiparuki
提出日時 2016-07-09 23:33:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,588 ms / 2,000 ms
コード長 1,350 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 165,544 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-21 11:06:18
合計ジャッジ時間 26,460 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1,584 ms
5,376 KB
testcase_24 AC 989 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 8 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 7 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 477 ms
5,376 KB
testcase_31 AC 475 ms
5,376 KB
testcase_32 AC 871 ms
5,504 KB
testcase_33 AC 874 ms
5,376 KB
testcase_34 AC 1,232 ms
5,376 KB
testcase_35 AC 1,224 ms
5,376 KB
testcase_36 AC 1,588 ms
5,376 KB
testcase_37 AC 442 ms
5,376 KB
testcase_38 AC 1,082 ms
5,376 KB
testcase_39 AC 534 ms
5,376 KB
testcase_40 AC 532 ms
5,376 KB
testcase_41 AC 1,518 ms
5,376 KB
testcase_42 AC 1,312 ms
5,376 KB
testcase_43 AC 145 ms
5,376 KB
testcase_44 AC 249 ms
5,376 KB
testcase_45 AC 826 ms
5,376 KB
testcase_46 AC 1,350 ms
5,376 KB
testcase_47 AC 657 ms
5,376 KB
testcase_48 AC 941 ms
5,376 KB
testcase_49 AC 353 ms
5,376 KB
testcase_50 AC 582 ms
5,376 KB
testcase_51 AC 383 ms
5,376 KB
testcase_52 AC 749 ms
5,376 KB
testcase_53 AC 978 ms
5,376 KB
testcase_54 AC 541 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll INF = numeric_limits<ll>::max();
ll N, M, A[500], K[500];

void solve(){
    ll r = -M;
    rep(i, N)r += A[i] * K[i];
    if(r < 0){
        puts("-1");
        return;
    }
    
    ll ans = 0;
    if(r >= A[N - 1] * A[N - 1]){
        ans += (r-A[N-1]*A[N-1]) / A[N-1];
        r -= ans * A[N-1];
    }

    vll dp(r+1, INF);
    dp[0] = ans;
    rep(i, N){
        ll a = A[i], m = r / a;
        for(ll x = 1; m; x <<= 1){
            ll y = min(m, x);
            m -= y;
            for(int j = (int)r; j >= 0; --j)if(dp[j]!=INF && j + y*a <= r){
                smin(dp[j + y*a], dp[j] + y);
            }
        }
    }
    cout << (dp.back() == INF ? -1 : dp.back()) << endl;
}

int main(){
    while(cin >> N >> M){
        rep(i, N)scanf("%lld", &A[i]);
        rep(i, N)scanf("%lld", &K[i]);
        solve();
    }
}
0