結果

問題 No.288 貯金箱の仕事
ユーザー 👑 hos.lyric
提出日時 2015-02-12 22:02:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,984 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 87,800 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-23 19:19:56
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 TLE * 1 -- * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int in()’:
main.cpp:34:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 | int in() { int x; scanf("%d", &x); return x; }
      |                   ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:54:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   54 |                         scanf("%d", &A[i]);
      |                         ~~~~~^~~~~~~~~~~~~
main.cpp:57:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |                         scanf("%lld", &K[i]);
      |                         ~~~~~^~~~~~~~~~~~~~~

ソースコード

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