結果
| 問題 | No.288 貯金箱の仕事 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-08 16:40:40 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 951 bytes |
| コンパイル時間 | 1,829 ms |
| コンパイル使用メモリ | 197,428 KB |
| 最終ジャッジ日時 | 2025-01-06 18:43:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 30 TLE * 9 |
ソースコード
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
int main()
{
int N;
ll M;
std::cin >> N >> M;
std::vector<int> A(N);
std::vector<ll> K(N);
for (int i = 0; i < N; i++) { std::cin >> A[i]; }
int max = 0;
for (int i = 0; i < N; i++) { std::cin >> K[i], M -= K[i] * A[i], max = std::max(max, A[i]); }
M = -M;
ll ans = std::max(0LL, M - max * max + 1) / max;
M -= ans * max;
std::vector<int> memo(max * max, max + 1);
auto dp = [&](auto&& self, const ll M) -> int {
if (M == 0) { return 0; }
if (M < 0) { return max + 1; }
if (memo[M] != max + 1) { return memo[M]; }
int ans = max;
for (const ll a : A) { ans = std::min(ans, self(self, M - a)); }
return memo[M] = ans + 1;
};
const int add = dp(dp, M);
std::cout << ans + (add == max + 1 ? -ans - 1 : add) << std::endl;
return 0;
}