結果

問題 No.1 道のショートカット
コンテスト
ユーザー らっしー(raccy)
提出日時 2014-12-07 17:36:30
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
TLE  
実行時間 -
コード長 887 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 103 ms
コンパイル使用メモリ 9,216 KB
実行使用メモリ 22,820 KB
最終ジャッジ日時 2026-03-29 19:41:52
合計ジャッジ時間 8,579 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 TLE * 1 -- * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

class Keiro
  def initialize(v, s, t, y, m)
    @num = v
    @s_ms = s
    @e_ms = t
    @costs = y
    @times = m
  end

  def min_time(s_machi, e_machi, coin)
    list = []
    @num.times do |i|
      if s_machi == @s_ms[i]
        nokori = coin - @costs[i]
        if nokori >= 0
          if e_machi == @e_ms[i]
            list << @times[i]
          else
            kt = min_time(@e_ms[i], e_machi, nokori)
            if kt
              list << kt + @times[i]
            end
          end
        end
      end
    end
    if list.empty?
      return nil
    else
      return list.min
    end
  end
end

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)

keiro = Keiro.new(v, s, t, y, m)
mt = keiro.min_time(1, n, c) || -1
puts mt
0