結果

問題 No.288 貯金箱の仕事
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-12 22:02:18
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,984 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 87,384 KB
実行使用メモリ 9,624 KB
最終ジャッジ日時 2023-09-06 00:12:22
合計ジャッジ時間 6,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 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 6 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 TLE -
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 <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template <typename T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <typename T> void chmax(T &t, const T &f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

const int LIM_N = 1000;
const int LIM_SUM = 1000 * 1000;

const Int INF = 1001001001001001001LL;

int N;
Int M;
int A[LIM_N + 10];
Int K[LIM_N + 10];

int ASum[LIM_N + 10];
Int dp[LIM_SUM * 2 + 10];

int main() {
	
	
	for (; ~scanf("%d%lld", &N, &M); ) {
		for (int i = 0; i < N; ++i) {
			scanf("%d", &A[i]);
		}
		for (int i = 0; i < N; ++i) {
			scanf("%lld", &K[i]);
		}
		partial_sum(A, A + N, ASum + 1);
		const int sum = ASum[N];
		Int target = -M;
		for (int i = 0; i < N; ++i) {
			target += A[i] * K[i];
		}
		if (target < 0) {
			puts("-1");
			continue;
		}
		memset(dp, 0x3f, sum << 3);
		dp[0] = 0;
		for (Int t = target, c = 1; t; t >>= 1, c <<= 1) {
			memset(dp + sum, 0x3f, sum << 3);
			for (int i = 0; i < N; ++i) {
				for (int x = sum + ASum[i + 1]; x >= A[i]; --x) {
					chmin(dp[x], dp[x - A[i]] + c);
				}
			}
			for (int x = 0; x < sum; ++x) {
				dp[x] = dp[x << 1 | (t & 1)];
			}
		}
		if (dp[0] >= INF) {
			puts("-1");
		} else {
			printf("%lld\n", dp[0]);
		}
	}
	
	return 0;
}
0