結果

問題 No.288 貯金箱の仕事
ユーザー fumofumofunifumofumofuni
提出日時 2021-09-08 23:35:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 588 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 2,291 ms
コンパイル使用メモリ 200,388 KB
実行使用メモリ 11,116 KB
最終ジャッジ日時 2023-08-27 15:00:23
合計ジャッジ時間 14,226 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
10,832 KB
testcase_01 AC 7 ms
10,764 KB
testcase_02 AC 10 ms
10,780 KB
testcase_03 AC 7 ms
10,756 KB
testcase_04 AC 9 ms
10,884 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 64 ms
10,892 KB
testcase_08 AC 22 ms
10,764 KB
testcase_09 AC 50 ms
11,032 KB
testcase_10 AC 55 ms
10,824 KB
testcase_11 AC 26 ms
10,768 KB
testcase_12 AC 49 ms
10,760 KB
testcase_13 AC 41 ms
10,832 KB
testcase_14 AC 48 ms
10,888 KB
testcase_15 AC 57 ms
10,708 KB
testcase_16 AC 52 ms
10,716 KB
testcase_17 AC 39 ms
10,952 KB
testcase_18 AC 29 ms
10,712 KB
testcase_19 AC 35 ms
10,880 KB
testcase_20 AC 24 ms
10,768 KB
testcase_21 AC 27 ms
11,096 KB
testcase_22 AC 50 ms
10,884 KB
testcase_23 AC 587 ms
11,032 KB
testcase_24 AC 431 ms
10,724 KB
testcase_25 AC 7 ms
10,760 KB
testcase_26 AC 8 ms
10,888 KB
testcase_27 AC 7 ms
10,728 KB
testcase_28 AC 8 ms
11,116 KB
testcase_29 AC 7 ms
10,876 KB
testcase_30 AC 151 ms
10,716 KB
testcase_31 AC 151 ms
10,716 KB
testcase_32 AC 296 ms
10,792 KB
testcase_33 AC 294 ms
10,784 KB
testcase_34 AC 439 ms
11,040 KB
testcase_35 AC 440 ms
10,820 KB
testcase_36 AC 588 ms
10,764 KB
testcase_37 AC 172 ms
10,716 KB
testcase_38 AC 405 ms
10,892 KB
testcase_39 AC 196 ms
10,876 KB
testcase_40 AC 202 ms
10,772 KB
testcase_41 AC 559 ms
10,828 KB
testcase_42 AC 489 ms
10,824 KB
testcase_43 AC 339 ms
10,712 KB
testcase_44 AC 238 ms
10,768 KB
testcase_45 AC 448 ms
10,760 KB
testcase_46 AC 492 ms
10,712 KB
testcase_47 AC 324 ms
11,068 KB
testcase_48 AC 355 ms
10,768 KB
testcase_49 AC 216 ms
10,884 KB
testcase_50 AC 282 ms
10,944 KB
testcase_51 AC 205 ms
10,900 KB
testcase_52 AC 287 ms
10,716 KB
testcase_53 AC 374 ms
10,964 KB
testcase_54 AC 260 ms
10,824 KB
testcase_55 AC 8 ms
10,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll n,m;cin >> n >>m;
    vl a(n);rep(i,n)cin >> a[i];
    ll sum=0;
    rep(i,n){
        ll k;cin >> k;
        sum+=k*a[i];
    }
    sum-=m;
    if(sum<0)cout << -1 << endl,exit(0);
    ll d=1e6;
    vl dp(d,INF);dp[0]=0;
    rep(i,n){
        rep(j,d){
            if(j-a[i]>=0)chmin(dp[j],dp[j-a[i]]+1);
        }
    }
    if(sum<d){
        if(dp[sum]==INF)cout << -1 << endl;
        else cout << dp[sum] << endl;
        return 0;
    }
    ll last=a.back();
    ll t=(sum-d)/last+1;
    ll ans=dp[sum-last*t]+t;
    if(ans>=INF)cout << -1 << endl;
    else cout << ans << endl;
}

0