結果

問題 No.288 貯金箱の仕事
ユーザー antaanta
提出日時 2015-10-11 18:49:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,025 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 80,568 KB
実行使用メモリ 4,776 KB
最終ジャッジ日時 2023-09-28 11:48:52
合計ジャッジ時間 5,220 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,420 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 156 ms
4,380 KB
testcase_24 AC 43 ms
4,444 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 155 ms
4,508 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int M;
	while(~scanf("%d%d", &N, &M)) {
		vector<int> A(N);
		for(int i = 0; i < N; ++ i)
			scanf("%d", &A[i]);
		long long sum = 0;
		for(int i = 0; i < N; ++ i) {
			long long K;
			scanf("%lld", &K);
			sum += K * A[i];
		}
		if(sum < M) {
			puts("-1");
			continue;
		}
		int X = A[N - 1];
		vector<vi> dp(X+1, vi(X, INF));
		dp[0][0] = 0;
		rep(i, X) rep(j, X) {
			int x = dp[i][j];
			if(x == INF) continue;
			rep(k, N) {
				int nj = j + A[k];
				if(nj < X) {
					amin(dp[i][nj], x + 1);
				} else {
					amin(dp[i + 1][nj - X], x);
				}
			}
		}
		long long Y = sum - M;
		long long quot = Y / X;
		int rem = Y % X;
		long long ans = INFL;
		rep(i, X) if(i <= quot) {
			int t = dp[i][rem];
			if(t < INF)
				amin(ans, t + quot);
		}
		if(ans == INFL)
			puts("-1");
		else
			printf("%lld\n", ans);
	}
	return 0;
}
0