結果

問題 No.1 道のショートカット
ユーザー らっしー(raccy)
提出日時 2014-12-07 17:36:30
言語 Ruby
(3.4.1)
結果
TLE  
実行時間 -
コード長 887 bytes
コンパイル時間 65 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-07-08 03:37:48
合計ジャッジ時間 9,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 TLE * 1 -- * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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