結果

問題 No.27 板の準備
ユーザー tshigtshig
提出日時 2016-08-23 15:49:42
言語 Ruby
(3.3.0)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 779 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 11,324 KB
実行使用メモリ 15,444 KB
最終ジャッジ日時 2023-08-27 04:31:54
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
15,260 KB
testcase_01 AC 174 ms
15,412 KB
testcase_02 AC 180 ms
15,204 KB
testcase_03 AC 175 ms
15,372 KB
testcase_04 AC 176 ms
15,240 KB
testcase_05 AC 174 ms
15,312 KB
testcase_06 AC 174 ms
15,444 KB
testcase_07 AC 175 ms
15,296 KB
testcase_08 AC 175 ms
15,216 KB
testcase_09 AC 174 ms
15,440 KB
testcase_10 AC 175 ms
15,444 KB
testcase_11 AC 174 ms
15,176 KB
testcase_12 AC 175 ms
15,388 KB
testcase_13 AC 175 ms
15,332 KB
testcase_14 AC 176 ms
15,240 KB
testcase_15 AC 176 ms
15,164 KB
testcase_16 AC 176 ms
15,284 KB
testcase_17 AC 176 ms
15,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Calc0027
  def initialize(args)
    args = args.map { |l| l.chomp.split(/\s+/) }
    @vs = args.shift.map(&:to_i)
  end

  def run
    min = nil
    (1..30).each do |a|
      (a..30).each do |b|
        (b..30).each do |c|
          r = calc_min([a, b, c])
          min = r if !min || r && min > r
        end
      end
    end
    min
  end

  def calc_min(bs)
    memo = Array.new(31)
    memo[0] = 0

    bs.each do |b|
      (1..30).each do |m|
        if m >= b 
          r = [memo[m], (memo[m - b] ? memo[m - b] + 1 : nil)].compact
          memo[m] = r.min unless r.empty?
        end
      end
    end

    r = @vs.map { |v| memo[v] }
    if r.all?
      r.inject(:+)
    else
      nil
    end
  end
end

puts Calc0027.new(STDIN.readlines).run if __FILE__ == $0
0