結果

問題 No.288 貯金箱の仕事
ユーザー mayoko_mayoko_
提出日時 2015-10-11 11:04:56
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,527 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 77,356 KB
実行使用メモリ 814,620 KB
最終ジャッジ日時 2023-09-28 11:42:32
合計ジャッジ時間 5,009 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
15,708 KB
testcase_01 AC 4 ms
7,460 KB
testcase_02 AC 6 ms
9,788 KB
testcase_03 AC 4 ms
5,332 KB
testcase_04 AC 6 ms
9,628 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 59 ms
101,616 KB
testcase_08 AC 20 ms
34,184 KB
testcase_09 AC 47 ms
81,132 KB
testcase_10 AC 51 ms
89,620 KB
testcase_11 AC 23 ms
40,220 KB
testcase_12 AC 45 ms
79,072 KB
testcase_13 AC 38 ms
64,784 KB
testcase_14 AC 44 ms
77,040 KB
testcase_15 AC 54 ms
95,572 KB
testcase_16 AC 47 ms
83,276 KB
testcase_17 AC 35 ms
60,692 KB
testcase_18 AC 25 ms
44,492 KB
testcase_19 AC 31 ms
54,512 KB
testcase_20 AC 20 ms
36,064 KB
testcase_21 AC 23 ms
40,224 KB
testcase_22 AC 45 ms
79,264 KB
testcase_23 MLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

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*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 i = 0; i < N; i++) for (int j = 0; j < MAXN*MAXN; j++) dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) for (int j = 0; j < MAXN*MAXN; j++) {
        if (i > 0) dp[i][j] = min(dp[i][j], dp[i-1][j]);
        if (A[i] <= j) dp[i][j] = min(dp[i][j], dp[i][j-A[i]] + 1);
    }
    ll ans = 0;
    ll T = sum-M;
    if (T > MAXN*MAXN) {
        ll cnt = T-MAXN*MAXN;
        ans += cnt/A[N-1]+1;
        T -= ans*A[N-1];
    }
    ans += dp[N-1][T];
    if (ans >= INF) ans = -1;
    cout << ans << endl;
    return 0;
}
0