結果

問題 No.1 道のショートカット
ユーザー yamaghyamagh
提出日時 2016-05-06 00:53:46
言語 Ruby
(3.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 732 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 11,500 KB
実行使用メモリ 15,592 KB
最終ジャッジ日時 2023-09-22 12:43:28
合計ジャッジ時間 5,669 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,228 KB
testcase_01 AC 82 ms
15,048 KB
testcase_02 AC 79 ms
15,176 KB
testcase_03 AC 80 ms
15,292 KB
testcase_04 AC 80 ms
15,032 KB
testcase_05 AC 84 ms
15,316 KB
testcase_06 AC 80 ms
15,312 KB
testcase_07 AC 80 ms
15,040 KB
testcase_08 AC 89 ms
15,304 KB
testcase_09 AC 84 ms
15,348 KB
testcase_10 AC 86 ms
15,352 KB
testcase_11 AC 93 ms
15,320 KB
testcase_12 AC 93 ms
15,484 KB
testcase_13 AC 93 ms
15,592 KB
testcase_14 AC 82 ms
15,052 KB
testcase_15 RE -
testcase_16 WA -
testcase_17 RE -
testcase_18 AC 82 ms
15,092 KB
testcase_19 AC 83 ms
15,280 KB
testcase_20 AC 83 ms
15,328 KB
testcase_21 AC 83 ms
15,276 KB
testcase_22 AC 81 ms
15,144 KB
testcase_23 AC 115 ms
15,588 KB
testcase_24 AC 114 ms
15,416 KB
testcase_25 AC 87 ms
15,088 KB
testcase_26 AC 84 ms
15,208 KB
testcase_27 AC 110 ms
15,304 KB
testcase_28 AC 81 ms
15,260 KB
testcase_29 AC 89 ms
15,400 KB
testcase_30 AC 84 ms
15,088 KB
testcase_31 AC 87 ms
15,132 KB
testcase_32 AC 84 ms
15,464 KB
testcase_33 AC 84 ms
15,152 KB
testcase_34 AC 95 ms
15,384 KB
testcase_35 AC 83 ms
15,312 KB
testcase_36 AC 85 ms
15,384 KB
testcase_37 AC 84 ms
15,316 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 81 ms
15,160 KB
testcase_41 WA -
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N=gets.to_i  # Nodes (2<=N<=50)
C=gets.to_i  # Costs (1<=C<=300)
V=gets.to_i  # Edges (1<=V<=1500)
S=gets.split.map{|m|m.to_i-1}  # FromTownNo
T=gets.split.map{|m|m.to_i-1}  # DestTownNo
Y=gets.split.map &:to_i        # Cost
M=gets.split.map &:to_i        # Time
MAX=999

tym=Array.new(S).map{Array.new(0)}
S.each.with_index{|e,i| tym[e] << { t: T[i], y:Y[i], m:M[i] }}

dp=Array.new(N).map{Array.new(C+1,MAX)}
dp[0][0]=0

N.times do |n|
  C.times do |c|
    next if dp[n][c]==MAX
    next if tym[n].nil?
    tym[n].each do |e|
      et=e[:t]
      ey=e[:y]+c
      next if C<ey
      em=e[:m]+dp[n][c]
      dp[et][ey]=[em, dp[et][ey]].min
    end
  end
end

#dp.each{|e|p e}

ans = [dp[N-1].min, MAX].min
puts ans==MAX ? -1 : ans
0