結果

問題 No.137 貯金箱の焦り
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-01-05 09:30:19
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 537 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 11,160 KB
実行使用メモリ 20,044 KB
最終ジャッジ日時 2023-09-03 22:02:26
合計ジャッジ時間 9,929 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,440 KB
testcase_01 AC 83 ms
15,152 KB
testcase_02 AC 89 ms
15,160 KB
testcase_03 AC 87 ms
15,300 KB
testcase_04 AC 216 ms
15,008 KB
testcase_05 AC 103 ms
15,012 KB
testcase_06 AC 146 ms
15,148 KB
testcase_07 AC 110 ms
15,152 KB
testcase_08 AC 120 ms
15,176 KB
testcase_09 AC 161 ms
15,008 KB
testcase_10 AC 113 ms
15,120 KB
testcase_11 AC 82 ms
15,160 KB
testcase_12 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

#!/usr/bin/env ruby

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

as_sum = Array.new(n + 1)
as_sum[0] = 0
n.times do |i|
  as_sum[i + 1] = as_sum[i] + as[i]
end
sum = as_sum[n]
dp = Array.new(sum * 2, 0)
dp[0] = 1

while m != 0
  n.times do |i|
    a = as[i]
    (sum - 1 + as_sum[i + 1]).downto(a) do |x|
      dp[x] += dp[x - a]
      if dp[x] >= 1234567891
        dp[x] -= 1234567891
      end
    end
  end
  sum.times do |x|
    dp[x] = dp[x << 1 | (m & 1)]
  end
  dp.fill(0, sum ... sum * 2)
  m >>= 1
end

p dp[0]
0