結果
| 問題 |
No.288 貯金箱の仕事
|
| コンテスト | |
| ユーザー |
maine_honzuki
|
| 提出日時 | 2021-05-13 10:52:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 976 bytes |
| コンパイル時間 | 2,041 ms |
| コンパイル使用メモリ | 195,696 KB |
| 最終ジャッジ日時 | 2025-01-21 10:30:15 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 WA * 1 TLE * 22 |
ソースコード
//https://ncode.syosetu.com/n4830bu/288/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll N, M;
cin >> N >> M;
vector<ll> A(N), K(N);
for (auto&& a : A) {
cin >> a;
}
for (auto&& k : K) {
cin >> k;
}
M *= -1;
for (int i = 0; i < N; i++) {
M += A[i] * K[i];
}
vector<ll> dp(610000, (ll)1e18 + 10);
dp[0] = 0;
ll maine = 1;
if (M > 0)
while (M) {
for (int i = 0; i < N; i++) {
for (int x = 600000; x >= 0; x--) {
dp[x + A[i]] = min(dp[x + A[i]], dp[x] + maine);
}
}
for (int i = 0; i < 300000; i++) {
dp[i] = dp[i * 2 + M % 2ll];
}
fill(dp.begin() + 300000, dp.end(), (ll)1e18 + 10);
M >>= 1;
maine <<= 1;
}
else
dp[0] = -1;
cout << (dp[0] > (ll)1e18 ? -1 : dp[0]) << endl;
}
maine_honzuki