結果

問題 No.1 道のショートカット
ユーザー wotsushiwotsushi
提出日時 2016-12-18 09:56:53
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 534 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 11,420 KB
実行使用メモリ 17,072 KB
最終ジャッジ日時 2023-09-22 12:53:29
合計ジャッジ時間 7,019 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,156 KB
testcase_01 AC 80 ms
15,024 KB
testcase_02 AC 77 ms
15,092 KB
testcase_03 AC 78 ms
15,212 KB
testcase_04 AC 79 ms
15,184 KB
testcase_05 AC 79 ms
15,308 KB
testcase_06 AC 79 ms
15,316 KB
testcase_07 AC 79 ms
15,164 KB
testcase_08 AC 168 ms
17,016 KB
testcase_09 RE -
testcase_10 AC 102 ms
15,992 KB
testcase_11 AC 113 ms
16,004 KB
testcase_12 AC 188 ms
17,072 KB
testcase_13 AC 186 ms
17,000 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 100 ms
15,756 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 137 ms
16,880 KB
testcase_24 AC 152 ms
17,032 KB
testcase_25 AC 109 ms
15,952 KB
testcase_26 AC 99 ms
15,708 KB
testcase_27 AC 137 ms
16,496 KB
testcase_28 RE -
testcase_29 AC 91 ms
15,736 KB
testcase_30 AC 81 ms
15,284 KB
testcase_31 AC 86 ms
15,628 KB
testcase_32 AC 142 ms
16,428 KB
testcase_33 AC 123 ms
16,048 KB
testcase_34 AC 144 ms
16,352 KB
testcase_35 AC 82 ms
15,196 KB
testcase_36 AC 95 ms
15,844 KB
testcase_37 AC 81 ms
15,452 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 AC 84 ms
15,064 KB
testcase_41 AC 80 ms
15,156 KB
testcase_42 RE -
testcase_43 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)].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