結果
| 問題 |
No.288 貯金箱の仕事
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-19 18:17:53 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,423 bytes |
| コンパイル時間 | 657 ms |
| コンパイル使用メモリ | 71,556 KB |
| 実行使用メモリ | 9,764 KB |
| 最終ジャッジ日時 | 2024-10-15 17:22:37 |
| 合計ジャッジ時間 | 8,626 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 1 TLE * 1 -- * 32 |
ソースコード
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const int W = 500;
const int infty = 1e9+7;
const ll inftyll = ll(1e18)+9;
int main() {
int n; ll m; scanf("%d%lld", &n, &m);
vector<int> a(n); repeat (i,n) scanf("%d", &a[i]);
vector<ll> k(n); repeat (i,n) scanf("%lld", &k[i]);
ll x = whole(inner_product, a, k.begin(), 0ll) - m;
ll ans = inftyll;
if (x >= 0) {
int l = min<ll>(1e6, x);
array<int,W+2> dp = {};
whole(fill, dp, infty);
dp[0] = 0;
repeat (acc,l) {
int i = acc % dp.size();
if (dp[i] == infty) continue;
repeat (j,n) {
setmin(dp[(i + a[j]) % dp.size()], dp[i] + 1);
if ((x - acc) % a[j] == 0) {
setmin(ans, dp[i] + (x - acc) / a[j]);
}
}
dp[i] = infty;
}
}
if (ans == inftyll) ans = -1;
printf("%lld\n", ans);
return 0;
}