結果
| 問題 |
No.288 貯金箱の仕事
|
| コンテスト | |
| ユーザー |
しらっ亭
|
| 提出日時 | 2016-03-16 01:33:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 1,271 ms |
| コンパイル使用メモリ | 158,824 KB |
| 実行使用メモリ | 814,720 KB |
| 最終ジャッジ日時 | 2024-10-01 07:05:40 |
| 合計ジャッジ時間 | 3,962 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | AC * 2 RE * 2 MLE * 1 -- * 48 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FORR(x,arr) for(auto&& x:arr)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
typedef long long ll;
// -------------------------------------
int n;
ll m;
ll a[500];
ll k[500];
template<class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T> inline T __lcm(T a, T b) { return a/__gcd(a,b)*b; }
void Main() {
cin >> n >> m;
ll ma=0;
REP(i, n) cin >> a[i];
REP(i, n) cin >> k[i];
ll s = -m;
ll lcm = 1;
REP(i, n) {
amax(ma, a[i]);
s += a[i] * k[i];
lcm = __lcm(lcm, a[i]);
}
if (s < 0) {
puts("-1");
return;
}
ll ans = (s - (s % lcm)) / ma;
s %= lcm;
int dp[s];
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
REP(i, n) {
REP(j, 1000001) {
if (dp[j] < 1e9) {
if (j+a[i] <= s) amin(dp[j+a[i]], dp[j]+1);
}
}
}
cout << (dp[s] > 1e9 ? -1 : (ans + dp[s])) << endl;
}
int main() {Main(); return 0; }
しらっ亭