結果

問題 No.1 道のショートカット
ユーザー wotsushiwotsushi
提出日時 2016-12-18 10:03:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 168 ms / 5,000 ms
コード長 552 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 11,540 KB
実行使用メモリ 17,108 KB
最終ジャッジ日時 2023-09-27 22:03:14
合計ジャッジ時間 6,375 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
15,012 KB
testcase_01 AC 71 ms
15,256 KB
testcase_02 AC 71 ms
15,280 KB
testcase_03 AC 69 ms
15,008 KB
testcase_04 AC 69 ms
15,252 KB
testcase_05 AC 73 ms
15,268 KB
testcase_06 AC 70 ms
15,276 KB
testcase_07 AC 71 ms
15,108 KB
testcase_08 AC 159 ms
16,996 KB
testcase_09 AC 117 ms
16,220 KB
testcase_10 AC 96 ms
15,836 KB
testcase_11 AC 106 ms
15,832 KB
testcase_12 AC 168 ms
17,100 KB
testcase_13 AC 168 ms
17,000 KB
testcase_14 AC 79 ms
15,516 KB
testcase_15 AC 72 ms
15,008 KB
testcase_16 AC 93 ms
15,660 KB
testcase_17 AC 76 ms
15,056 KB
testcase_18 AC 77 ms
15,588 KB
testcase_19 AC 85 ms
15,808 KB
testcase_20 AC 84 ms
15,588 KB
testcase_21 AC 91 ms
15,600 KB
testcase_22 AC 80 ms
15,640 KB
testcase_23 AC 124 ms
17,004 KB
testcase_24 AC 141 ms
17,108 KB
testcase_25 AC 97 ms
15,952 KB
testcase_26 AC 89 ms
15,680 KB
testcase_27 AC 120 ms
16,352 KB
testcase_28 AC 74 ms
15,272 KB
testcase_29 AC 85 ms
15,932 KB
testcase_30 AC 76 ms
15,412 KB
testcase_31 AC 83 ms
15,488 KB
testcase_32 AC 128 ms
16,404 KB
testcase_33 AC 115 ms
15,904 KB
testcase_34 AC 130 ms
16,328 KB
testcase_35 AC 71 ms
15,220 KB
testcase_36 AC 80 ms
15,776 KB
testcase_37 AC 73 ms
15,292 KB
testcase_38 AC 73 ms
15,216 KB
testcase_39 AC 86 ms
15,932 KB
testcase_40 AC 83 ms
15,136 KB
testcase_41 AC 74 ms
15,076 KB
testcase_42 AC 72 ms
15,024 KB
testcase_43 AC 71 ms
15,212 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)
e = S.zip(T, Y, M).group_by {|(s, t, y, m)| s}
dp = Array.new(N + 1) { Array.new(C + 1, Float::INFINITY)}
dp[1][C] = 0
[*1..(N - 1)].select {|s| e[s]}.product([*1..C]).each do |(s, c)|
  e[s].select {|_, t, y, m| y <= c}.each do |(_, t, y, m)|
    dp[t][c - y] = [dp[t][c - y], dp[s][c] + m].min
  end
end
ans = if dp[N].min < Float::INFINITY
        dp[N].min
      else
        -1
      end
puts ans
0