結果

問題 No.1 道のショートカット
ユーザー らっしー(raccy)らっしー(raccy)
提出日時 2014-12-07 19:31:25
言語 Ruby
(3.3.0)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 916 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 11,272 KB
実行使用メモリ 15,600 KB
最終ジャッジ日時 2023-09-27 21:37:13
合計ジャッジ時間 6,038 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
15,188 KB
testcase_01 AC 74 ms
15,156 KB
testcase_02 AC 73 ms
15,296 KB
testcase_03 AC 73 ms
15,196 KB
testcase_04 AC 72 ms
15,084 KB
testcase_05 AC 71 ms
15,296 KB
testcase_06 AC 74 ms
15,120 KB
testcase_07 AC 72 ms
15,312 KB
testcase_08 AC 81 ms
15,520 KB
testcase_09 AC 75 ms
15,304 KB
testcase_10 AC 79 ms
15,324 KB
testcase_11 AC 89 ms
15,424 KB
testcase_12 AC 101 ms
15,452 KB
testcase_13 AC 101 ms
15,468 KB
testcase_14 AC 74 ms
15,156 KB
testcase_15 AC 75 ms
15,160 KB
testcase_16 AC 76 ms
15,092 KB
testcase_17 AC 74 ms
15,036 KB
testcase_18 AC 75 ms
15,300 KB
testcase_19 AC 72 ms
15,088 KB
testcase_20 AC 75 ms
15,236 KB
testcase_21 AC 74 ms
15,292 KB
testcase_22 AC 75 ms
15,188 KB
testcase_23 AC 122 ms
15,600 KB
testcase_24 AC 119 ms
15,412 KB
testcase_25 AC 83 ms
15,204 KB
testcase_26 AC 76 ms
15,268 KB
testcase_27 AC 108 ms
15,316 KB
testcase_28 AC 73 ms
15,036 KB
testcase_29 AC 83 ms
15,336 KB
testcase_30 AC 75 ms
15,260 KB
testcase_31 AC 78 ms
15,244 KB
testcase_32 AC 84 ms
15,444 KB
testcase_33 AC 79 ms
15,280 KB
testcase_34 AC 105 ms
15,388 KB
testcase_35 AC 75 ms
15,196 KB
testcase_36 AC 76 ms
15,096 KB
testcase_37 AC 79 ms
15,160 KB
testcase_38 AC 70 ms
15,092 KB
testcase_39 AC 73 ms
15,156 KB
testcase_40 AC 76 ms
15,160 KB
testcase_41 AC 74 ms
15,144 KB
testcase_42 AC 71 ms
15,048 KB
testcase_43 AC 75 ms
15,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
c = gets.to_i
v = gets.to_i
s = gets.split.map(&:to_i)
t = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
m = gets.split.map(&:to_i)

list = []
v.times do |i|
  list << [s[i], t[i], y[i], m[i]]
end
list.sort!{|a, b| a[0] <=> b[0]}

all_pats = {}
all_pats[1] = {c => 0}
list.each do |keiro|
  if all_pats[keiro[0]]
    all_pats[keiro[0]].each do |coin, time|
      nokori = coin - keiro[2]
      if nokori >= 0
        if all_pats[keiro[1]].nil?
          all_pats[keiro[1]] = {}
        end
        if all_pats[keiro[1]][nokori].nil? ||
            all_pats[keiro[1]][nokori] > (time + keiro[3])
          all_pats[keiro[1]][nokori] = time + keiro[3]
        end
      end
    end
  end
end

min_time = nil
if all_pats[n]
  all_pats[n].each do |coin, time|
    if min_time.nil? || min_time > time
      min_time = time
    end
  end
end
puts min_time || -1
0