結果

問題 No.555 世界史のレポート
ユーザー cympfhcympfh
提出日時 2017-08-25 18:27:34
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 43 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-23 15:20:20
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,288 KB
testcase_01 AC 88 ms
12,288 KB
testcase_02 AC 100 ms
12,672 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 121 ms
12,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def min(a, b)
  return b if a == nil
  return a if b == nil
  [a, b].min
end

def goodness(a, b, cost)
  a + b - cost
end

n = gets.to_i
c, v = gets.split.map(&:to_i)
ans = nil

q = [[1, 0, 0]]

n.times do

  r = []
  q.each do |a, b, cost|
    if a >= n
      ans = min(ans, cost)
    else
      r << [a + a, a, cost + c + v]
      r << [a + b, b, cost + v]
    end
  end

  q = r.sort_by {|a, b, cost| -goodness(a, b, cost)}[0...100]

end

p ans
0