結果

問題 No.288 貯金箱の仕事
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-02-12 22:12:41
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 802 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 22,124 KB
最終ジャッジ日時 2023-09-06 00:12:30
合計ジャッジ時間 8,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
19,628 KB
testcase_01 AC 84 ms
15,380 KB
testcase_02 AC 85 ms
15,208 KB
testcase_03 AC 83 ms
15,148 KB
testcase_04 AC 82 ms
15,152 KB
testcase_05 AC 84 ms
15,348 KB
testcase_06 AC 82 ms
15,160 KB
testcase_07 AC 85 ms
15,244 KB
testcase_08 AC 82 ms
15,184 KB
testcase_09 AC 84 ms
15,264 KB
testcase_10 AC 85 ms
15,232 KB
testcase_11 AC 84 ms
15,376 KB
testcase_12 AC 89 ms
15,128 KB
testcase_13 AC 84 ms
15,064 KB
testcase_14 AC 86 ms
15,180 KB
testcase_15 AC 86 ms
15,168 KB
testcase_16 AC 83 ms
15,156 KB
testcase_17 AC 85 ms
15,144 KB
testcase_18 AC 85 ms
15,264 KB
testcase_19 AC 84 ms
15,160 KB
testcase_20 AC 85 ms
15,200 KB
testcase_21 AC 84 ms
15,064 KB
testcase_22 AC 83 ms
15,188 KB
testcase_23 AC 129 ms
15,208 KB
testcase_24 AC 103 ms
15,184 KB
testcase_25 AC 220 ms
19,576 KB
testcase_26 AC 219 ms
19,548 KB
testcase_27 AC 220 ms
19,388 KB
testcase_28 AC 220 ms
19,532 KB
testcase_29 AC 220 ms
19,456 KB
testcase_30 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:50: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

#!/usr/bin/env ruby

INF = 10**18 + 1;

n, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
ks = gets.split.map(&:to_i)

lim = as[-1]
dp = []
loop do
  dp = (0 .. lim).map{ INF }
  dp[0] = 0
  as.each do |a|
    a.upto(lim) do |x|
      if dp[x] > dp[x - a] + 1
        dp[x] = dp[x - a] + 1
      end
    end
  end
  if lim >= as[-1] then
    ok = true
    lim.downto(lim - as[-1]) do |x|
      ok &&= (dp[x] == INF || dp[x] == dp[x - as[-1]] + 1)
    end
    if ok then
      break
    end
  end
  lim <<= 1
end

STDERR.puts lim

target = -m
n.times do |i|
  target += as[i] * ks[i];
end

if target < 0
  ans = INF
elsif target < lim
  ans = dp[target]
else
  greed = ((target - lim) + as[-1] - 1) / as[-1]
  ans = greed + dp[target - as[-1] * greed]
end

if ans >= INF
  p -1
else
  p ans
end
0