結果

問題 No.288 貯金箱の仕事
ユーザー しらっ亭しらっ亭
提出日時 2016-03-16 01:33:43
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,532 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 160,524 KB
実行使用メモリ 814,464 KB
最終ジャッジ日時 2024-04-08 14:14:57
合計ジャッジ時間 3,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 MLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

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

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