結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00-sample-01.txt AC 3 ms
1,560 KB
00-sample-02.txt AC 3 ms
1,552 KB
00-sample-03.txt AC 3 ms
1,548 KB
01-small-01.txt AC 3 ms
1,548 KB
01-small-02.txt AC 3 ms
1,548 KB
01-small-03.txt AC 3 ms
1,528 KB
01-small-04.txt AC 3 ms
1,536 KB
01-small-05.txt AC 4 ms
1,572 KB
01-small-06.txt AC 3 ms
1,568 KB
01-small-07.txt AC 4 ms
1,576 KB
01-small-08.txt AC 5 ms
1,572 KB
01-small-09.txt AC 3 ms
1,568 KB
01-small-10.txt AC 4 ms
1,572 KB
01-small-11.txt AC 3 ms
1,572 KB
01-small-12.txt AC 4 ms
1,568 KB
01-small-13.txt AC 4 ms
1,576 KB
01-small-14.txt AC 4 ms
1,572 KB
01-small-15.txt AC 4 ms
1,568 KB
01-small-16.txt AC 4 ms
1,572 KB
01-small-17.txt AC 4 ms
1,576 KB
01-small-18.txt AC 3 ms
1,568 KB
01-small-19.txt AC 3 ms
1,568 KB
01-small-20.txt AC 4 ms
1,576 KB
02-large-01.txt AC 1,410 ms
3,408 KB
02-large-02.txt AC 912 ms
3,408 KB
02-large-03.txt AC 9 ms
3,412 KB
02-large-04.txt AC 10 ms
3,412 KB
02-large-05.txt AC 9 ms
3,412 KB
02-large-06.txt AC 9 ms
3,412 KB
02-large-07.txt AC 9 ms
3,408 KB
02-large-08.txt AC 424 ms
3,412 KB
02-large-09.txt AC 425 ms
3,412 KB
02-large-10.txt AC 778 ms
3,408 KB
02-large-11.txt AC 772 ms
3,408 KB
02-large-12.txt AC 1,091 ms
3,408 KB
02-large-13.txt AC 1,093 ms
3,412 KB
02-large-14.txt AC 1,405 ms
3,412 KB
02-large-15.txt AC 393 ms
3,408 KB
02-large-16.txt AC 964 ms
3,408 KB
02-large-17.txt AC 475 ms
3,412 KB
02-large-18.txt AC 473 ms
3,408 KB
02-large-19.txt AC 1,346 ms
3,412 KB
02-large-20.txt AC 1,172 ms
3,408 KB
02-large-21.txt AC 129 ms
1,828 KB
02-large-22.txt AC 220 ms
2,092 KB
02-large-23.txt AC 738 ms
2,880 KB
02-large-24.txt AC 1,203 ms
3,408 KB
02-large-25.txt AC 584 ms
2,884 KB
02-large-26.txt AC 845 ms
3,144 KB
02-large-27.txt AC 315 ms
2,620 KB
02-large-28.txt AC 519 ms
2,884 KB
02-large-29.txt AC 343 ms
2,616 KB
02-large-30.txt AC 668 ms
3,144 KB
02-large-31.txt AC 872 ms
3,144 KB
02-large-32.txt AC 479 ms
2,884 KB
challenge01.txt AC 2 ms
1,556 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