結果

問題 No.288 貯金箱の仕事
ユーザー しらっ亭しらっ亭
提出日時 2016-03-16 01:29:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,486 bytes
コンパイル時間 1,235 ms
コンパイル使用メモリ 159,888 KB
実行使用メモリ 7,276 KB
最終ジャッジ日時 2024-04-08 14:14:36
合計ジャッジ時間 16,089 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
7,276 KB
testcase_01 AC 5 ms
7,276 KB
testcase_02 AC 6 ms
7,276 KB
testcase_03 AC 4 ms
7,276 KB
testcase_04 AC 6 ms
7,276 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 17 ms
7,276 KB
testcase_09 RE -
testcase_10 AC 42 ms
7,276 KB
testcase_11 RE -
testcase_12 AC 36 ms
7,276 KB
testcase_13 RE -
testcase_14 AC 34 ms
7,276 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 27 ms
7,276 KB
testcase_18 RE -
testcase_19 AC 25 ms
7,276 KB
testcase_20 AC 17 ms
7,276 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 6 ms
7,276 KB
testcase_26 AC 5 ms
7,276 KB
testcase_27 AC 5 ms
7,276 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 132 ms
7,276 KB
testcase_31 AC 132 ms
7,276 KB
testcase_32 AC 257 ms
7,276 KB
testcase_33 AC 256 ms
7,276 KB
testcase_34 AC 382 ms
7,276 KB
testcase_35 AC 382 ms
7,276 KB
testcase_36 RE -
testcase_37 AC 135 ms
7,276 KB
testcase_38 RE -
testcase_39 AC 170 ms
7,276 KB
testcase_40 AC 174 ms
7,276 KB
testcase_41 RE -
testcase_42 RE -
testcase_43 AC 243 ms
7,276 KB
testcase_44 RE -
testcase_45 AC 386 ms
7,276 KB
testcase_46 AC 421 ms
7,276 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 AC 174 ms
7,276 KB
testcase_50 RE -
testcase_51 AC 172 ms
7,276 KB
testcase_52 AC 251 ms
7,276 KB
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 6 ms
7,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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; }

int dp[1000001];

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]);
  }

  ll ans = (s - (s % lcm)) / ma;
  s %= lcm;

  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; }
0