結果

問題 No.288 貯金箱の仕事
ユーザー pekempeypekempey
提出日時 2015-10-09 23:56:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 2,969 ms
コンパイル使用メモリ 145,172 KB
実行使用メモリ 6,236 KB
最終ジャッジ日時 2023-09-27 10:38:08
合計ジャッジ時間 8,352 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,948 KB
testcase_01 AC 5 ms
5,932 KB
testcase_02 AC 5 ms
5,928 KB
testcase_03 AC 4 ms
5,936 KB
testcase_04 AC 6 ms
6,144 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 12 ms
6,068 KB
testcase_09 WA -
testcase_10 AC 26 ms
5,992 KB
testcase_11 WA -
testcase_12 AC 24 ms
5,936 KB
testcase_13 WA -
testcase_14 AC 23 ms
5,952 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 19 ms
6,012 KB
testcase_18 WA -
testcase_19 AC 17 ms
6,080 KB
testcase_20 AC 13 ms
6,064 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 5 ms
6,012 KB
testcase_26 AC 5 ms
6,012 KB
testcase_27 AC 5 ms
6,016 KB
testcase_28 AC 5 ms
5,956 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 155 ms
5,932 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 97 ms
6,012 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 5 ms
5,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define GET_MACRO(a, b, c, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define rep2(i, a) rep3 (i, 0, a)
#define rep3(i, a, b) for (int i = (a); i < (b); i++)
#define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__)
#define repr2(i, a) repr3 (i, 0, a)
#define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define chmin(a, b) ((b) < a && (a = (b), true))
#define chmax(a, b) (a < (b) && (a = (b), true))
using namespace std;
typedef long long ll;

const ll inf = 1e9;
const ll MX = 333333;
ll N, M;
ll A[500], K[500];
int dp[2][MX];

ll solve(ll D) {
	rep (i, 2) rep (j, MX) dp[i][j] = inf;
	dp[0][0] = 0;
	rep (i, N) {
		rep (j, MX) {
			chmin(dp[(i + 1) % 2][j], dp[i % 2][j]);
			if (j - A[i] >= 0) {
				chmin(dp[(i + 1) % 2][j], dp[(i + 1) % 2][j - A[i]] + 1);
			}
		}
	}
	if (D < MX) {
		if (dp[N % 2][D] == inf) return -1;
		return dp[N % 2][D];
	} else {
		ll res = 2e18;
		rep (i, N) {
			ll num = (D - MX) / A[i];
			cerr << D - num * A[i] << endl;
			ll cand = dp[N % 2][D - num * A[i]] + num;
			chmin(res, cand);
		}
		return res;
	}
}

int main() {
	cin >> N >> M;
	rep (i, N) cin >> A[i];
	rep (i, N) cin >> K[i];
	ll mx = 0;
	rep (i, N) mx += A[i] * K[i];
	ll D = mx - M;
	if (D < 0) {
		cout << -1 << endl;	
	} else {
		ll ans = solve(D);
		cout << ans << endl;
	}
	return 0;
}
0