結果

問題 No.288 貯金箱の仕事
ユーザー paruki
提出日時 2016-07-09 23:33:28
言語 C++14
(gcc 8.2.0)
結果
AC  
実行時間 1,399 ms
コード長 1,350 Byte
コンパイル時間 1,324 ms
使用メモリ 3,404 KB
最終ジャッジ日時 2019-07-10 07:00:20

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00-sample-01.txt AC 3 ms
1,560 KB
00-sample-02.txt AC 3 ms
1,544 KB
00-sample-03.txt AC 3 ms
1,540 KB
01-small-01.txt AC 3 ms
1,540 KB
01-small-02.txt AC 2 ms
1,544 KB
01-small-03.txt AC 3 ms
1,524 KB
01-small-04.txt AC 3 ms
1,532 KB
01-small-05.txt AC 4 ms
1,568 KB
01-small-06.txt AC 3 ms
1,564 KB
01-small-07.txt AC 4 ms
1,564 KB
01-small-08.txt AC 3 ms
1,568 KB
01-small-09.txt AC 3 ms
1,560 KB
01-small-10.txt AC 4 ms
1,564 KB
01-small-11.txt AC 4 ms
1,568 KB
01-small-12.txt AC 3 ms
1,560 KB
01-small-13.txt AC 3 ms
1,564 KB
01-small-14.txt AC 4 ms
1,564 KB
01-small-15.txt AC 3 ms
1,560 KB
01-small-16.txt AC 3 ms
1,564 KB
01-small-17.txt AC 4 ms
1,564 KB
01-small-18.txt AC 4 ms
1,560 KB
01-small-19.txt AC 3 ms
1,564 KB
01-small-20.txt AC 4 ms
1,568 KB
02-large-01.txt AC 1,399 ms
3,400 KB
02-large-02.txt AC 1,011 ms
3,400 KB
02-large-03.txt AC 9 ms
3,404 KB
02-large-04.txt AC 10 ms
3,400 KB
02-large-05.txt AC 9 ms
3,396 KB
02-large-06.txt AC 10 ms
3,400 KB
02-large-07.txt AC 9 ms
3,400 KB
02-large-08.txt AC 422 ms
3,400 KB
02-large-09.txt AC 423 ms
3,404 KB
02-large-10.txt AC 769 ms
3,400 KB
02-large-11.txt AC 770 ms
3,404 KB
02-large-12.txt AC 1,084 ms
3,404 KB
02-large-13.txt AC 1,079 ms
3,400 KB
02-large-14.txt AC 1,398 ms
3,400 KB
02-large-15.txt AC 388 ms
3,400 KB
02-large-16.txt AC 958 ms
3,404 KB
02-large-17.txt AC 469 ms
3,404 KB
02-large-18.txt AC 470 ms
3,404 KB
02-large-19.txt AC 1,338 ms
3,400 KB
02-large-20.txt AC 1,159 ms
3,404 KB
02-large-21.txt AC 129 ms
1,820 KB
02-large-22.txt AC 223 ms
2,084 KB
02-large-23.txt AC 743 ms
2,876 KB
02-large-24.txt AC 1,207 ms
3,400 KB
02-large-25.txt AC 578 ms
2,872 KB
02-large-26.txt AC 830 ms
3,136 KB
02-large-27.txt AC 312 ms
2,604 KB
02-large-28.txt AC 512 ms
2,872 KB
02-large-29.txt AC 338 ms
2,608 KB
02-large-30.txt AC 661 ms
3,136 KB
02-large-31.txt AC 872 ms
3,136 KB
02-large-32.txt AC 493 ms
2,876 KB
challenge01.txt AC 3 ms
1,548 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