結果

問題 No.288 貯金箱の仕事
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-12 22:01:17
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,009 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 92,432 KB
実行使用メモリ 6,204 KB
最終ジャッジ日時 2023-09-02 19:48:15
合計ジャッジ時間 6,966 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 6 ms
5,672 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 2 ms
4,368 KB
testcase_20 AC 1 ms
4,372 KB
testcase_21 AC 1 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 209 ms
5,940 KB
testcase_24 AC 99 ms
6,192 KB
testcase_25 AC 3 ms
5,356 KB
testcase_26 AC 3 ms
5,636 KB
testcase_27 AC 4 ms
5,948 KB
testcase_28 AC 4 ms
5,676 KB
testcase_29 AC 3 ms
5,092 KB
testcase_30 AC 55 ms
4,368 KB
testcase_31 AC 55 ms
5,412 KB
testcase_32 AC 108 ms
6,204 KB
testcase_33 AC 108 ms
6,160 KB
testcase_34 AC 160 ms
5,740 KB
testcase_35 AC 158 ms
4,372 KB
testcase_36 AC 209 ms
4,896 KB
testcase_37 AC 60 ms
4,692 KB
testcase_38 AC 142 ms
5,692 KB
testcase_39 AC 71 ms
5,688 KB
testcase_40 AC 73 ms
4,896 KB
testcase_41 AC 200 ms
4,844 KB
testcase_42 AC 174 ms
5,420 KB
testcase_43 AC 124 ms
5,640 KB
testcase_44 AC 38 ms
5,424 KB
testcase_45 AC 114 ms
5,140 KB
testcase_46 AC 177 ms
5,420 KB
testcase_47 AC 88 ms
4,372 KB
testcase_48 AC 124 ms
5,420 KB
testcase_49 AC 52 ms
4,372 KB
testcase_50 AC 76 ms
4,844 KB
testcase_51 AC 52 ms
4,376 KB
testcase_52 AC 96 ms
4,880 KB
testcase_53 AC 126 ms
5,152 KB
testcase_54 AC 72 ms
4,376 KB
testcase_55 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.stdio, std.string;

immutable INF = 10L^^18 + 1;

void main() {
	string[] tokens;
	tokens = readln.chomp.split(" ");
	const N = tokens[0].to!int;
	const M = tokens[1].to!long;
	tokens = readln.chomp.split(" ");
	auto A = new int[N];
	foreach (i; 0 .. N) {
		A[i] = tokens[i].to!int;
	}
	tokens = readln.chomp.split(" ");
	auto K = new long[N];
	foreach (i; 0 .. N) {
		K[i] = tokens[i].to!long;
	}
	
	const lim = A[$ - 1]^^2;
	auto dp = new long[lim + 1];
	dp[] = INF;
	dp[0] = 0;
	foreach (i; 0 .. N) {
		foreach (x; A[i] .. lim + 1) {
			if (dp[x] > dp[x - A[i]] + 1) {
				dp[x] = dp[x - A[i]] + 1;
			}
		}
	}
	long target = -M;
	foreach (i; 0 .. N) {
		target += A[i] * K[i];
	}
	long ans;
	if (target < 0) {
		ans = INF;
	} else if (target < lim) {
		ans = dp[cast(size_t)(target)];
	} else {
		const greed = ((target - lim) + A[$ - 1] - 1) / A[$ - 1];
		ans = greed + dp[cast(size_t)(target - A[$ - 1] * greed)];
	}
	if (ans >= INF) {
		writeln(-1);
	} else {
		writeln(ans);
	}
}
0