結果

問題 No.288 貯金箱の仕事
ユーザー mayoko_mayoko_
提出日時 2015-10-11 11:38:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 77,340 KB
実行使用メモリ 5,584 KB
最終ジャッジ日時 2023-09-28 11:43:38
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,396 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 157 ms
5,460 KB
testcase_24 AC 80 ms
5,316 KB
testcase_25 AC 3 ms
5,584 KB
testcase_26 AC 4 ms
5,320 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 4 ms
5,320 KB
testcase_29 AC 3 ms
5,368 KB
testcase_30 AC 43 ms
5,324 KB
testcase_31 AC 43 ms
5,316 KB
testcase_32 AC 81 ms
5,388 KB
testcase_33 AC 82 ms
5,384 KB
testcase_34 AC 119 ms
5,304 KB
testcase_35 AC 120 ms
5,432 KB
testcase_36 AC 157 ms
5,316 KB
testcase_37 AC 47 ms
5,420 KB
testcase_38 AC 108 ms
5,344 KB
testcase_39 AC 54 ms
5,384 KB
testcase_40 AC 56 ms
5,492 KB
testcase_41 AC 151 ms
5,328 KB
testcase_42 AC 132 ms
5,332 KB
testcase_43 AC 93 ms
5,380 KB
testcase_44 AC 29 ms
4,380 KB
testcase_45 AC 86 ms
4,740 KB
testcase_46 AC 134 ms
5,312 KB
testcase_47 AC 66 ms
4,892 KB
testcase_48 AC 92 ms
5,396 KB
testcase_49 AC 40 ms
4,916 KB
testcase_50 AC 58 ms
4,812 KB
testcase_51 AC 40 ms
4,760 KB
testcase_52 AC 74 ms
5,244 KB
testcase_53 AC 95 ms
5,232 KB
testcase_54 AC 55 ms
4,844 KB
testcase_55 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 501;
const ll INF = 1ll<<55;
int A[MAXN];
ll K[MAXN];
int N;
ll M;

ll dp[MAXN*MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    ll sum = 0;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) {
        cin >> K[i];
        sum += A[i]*K[i];
    }
    if (sum < M) {
        cout << -1 << endl;
        return 0;
    }
    for (int j = 0; j <= A[N-1]*A[N-1]; j++) dp[j] = INF;
    dp[0] = 0;
    for (int i = 0; i < N; i++) for (int j = 0; j <= A[N-1]*A[N-1]; j++) {
        if (A[i] <= j) dp[j] = min(dp[j], dp[j-A[i]] + 1);
    }
    ll ans = 0;
    ll T = sum-M;
    if (T > A[N-1]*A[N-1]) {
        ll cnt = T-A[N-1]*A[N-1];
        ans += cnt/A[N-1]+1;
        T -= ans*A[N-1];
    }
    ans += dp[T];
    if (ans >= INF) ans = -1;
    cout << ans << endl;
    return 0;
}
0