結果

問題 No.288 貯金箱の仕事
ユーザー しらっ亭しらっ亭
提出日時 2016-03-16 01:43:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 160,268 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 14:15:16
合計ジャッジ時間 6,745 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 1 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 2 ms
6,548 KB
testcase_22 AC 2 ms
6,548 KB
testcase_23 AC 282 ms
6,548 KB
testcase_24 AC 88 ms
6,548 KB
testcase_25 AC 3 ms
6,548 KB
testcase_26 AC 3 ms
6,548 KB
testcase_27 AC 3 ms
6,548 KB
testcase_28 AC 3 ms
6,548 KB
testcase_29 AC 3 ms
6,548 KB
testcase_30 AC 74 ms
6,548 KB
testcase_31 AC 74 ms
6,548 KB
testcase_32 AC 145 ms
6,548 KB
testcase_33 AC 145 ms
6,548 KB
testcase_34 AC 213 ms
6,548 KB
testcase_35 AC 213 ms
6,548 KB
testcase_36 AC 280 ms
6,548 KB
testcase_37 AC 83 ms
6,548 KB
testcase_38 AC 194 ms
6,548 KB
testcase_39 AC 96 ms
6,548 KB
testcase_40 AC 98 ms
6,548 KB
testcase_41 AC 271 ms
6,548 KB
testcase_42 AC 236 ms
6,548 KB
testcase_43 AC 168 ms
6,548 KB
testcase_44 AC 50 ms
6,548 KB
testcase_45 AC 154 ms
6,548 KB
testcase_46 AC 240 ms
6,548 KB
testcase_47 AC 117 ms
6,548 KB
testcase_48 AC 165 ms
6,548 KB
testcase_49 AC 72 ms
6,548 KB
testcase_50 AC 103 ms
6,548 KB
testcase_51 AC 70 ms
6,548 KB
testcase_52 AC 131 ms
6,548 KB
testcase_53 AC 174 ms
6,548 KB
testcase_54 AC 95 ms
6,548 KB
testcase_55 AC 2 ms
6,548 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; }

void Main() {
  cin >> n >> m;
  ll ma=0;
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> k[i];

  ll s = -m;
  REP(i, n) {
    amax(ma, a[i]);
    s += a[i] * k[i];
  }

  if (s < 0) {
    puts("-1");
    return;
  }

  ll ma2=ma*ma;
  ll ans = (s - s % ma2) / ma;
  s %= ma2;

  int dp[ma2+1];
  memset(dp, 0x3f, sizeof(dp));

  dp[0] = 0;
  REP(i, n) {
    REP(j, ma2+1) {
      if (dp[j] < 1e9) {
        if (j+a[i] <= ma2) amin(dp[j+a[i]], dp[j]+1);
      }
    }
  }
  cout << (dp[s] > 1e9 ? -1 : (ans + dp[s])) << endl;
}
int main() {Main(); return 0; }
0