結果

問題 No.1 道のショートカット
ユーザー DialBirdDialBird
提出日時 2019-07-03 08:54:56
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,684 ms / 5,000 ms
コード長 592 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 11,288 KB
実行使用メモリ 15,588 KB
最終ジャッジ日時 2023-09-27 22:21:19
合計ジャッジ時間 15,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,032 KB
testcase_01 AC 76 ms
15,108 KB
testcase_02 AC 74 ms
15,072 KB
testcase_03 AC 73 ms
15,272 KB
testcase_04 AC 74 ms
15,340 KB
testcase_05 AC 79 ms
15,112 KB
testcase_06 AC 72 ms
15,032 KB
testcase_07 AC 74 ms
15,272 KB
testcase_08 AC 1,360 ms
15,396 KB
testcase_09 AC 770 ms
15,324 KB
testcase_10 AC 417 ms
15,356 KB
testcase_11 AC 477 ms
15,448 KB
testcase_12 AC 1,684 ms
15,588 KB
testcase_13 AC 1,673 ms
15,584 KB
testcase_14 AC 111 ms
15,372 KB
testcase_15 AC 78 ms
15,288 KB
testcase_16 AC 275 ms
15,404 KB
testcase_17 AC 77 ms
15,208 KB
testcase_18 AC 125 ms
15,292 KB
testcase_19 AC 151 ms
15,428 KB
testcase_20 AC 198 ms
15,288 KB
testcase_21 AC 194 ms
15,544 KB
testcase_22 AC 130 ms
15,248 KB
testcase_23 AC 434 ms
15,464 KB
testcase_24 AC 482 ms
15,356 KB
testcase_25 AC 228 ms
15,212 KB
testcase_26 AC 157 ms
15,312 KB
testcase_27 AC 688 ms
15,464 KB
testcase_28 AC 77 ms
15,128 KB
testcase_29 AC 178 ms
15,428 KB
testcase_30 AC 86 ms
15,160 KB
testcase_31 AC 99 ms
15,272 KB
testcase_32 AC 778 ms
15,428 KB
testcase_33 AC 509 ms
15,316 KB
testcase_34 AC 544 ms
15,360 KB
testcase_35 AC 79 ms
15,260 KB
testcase_36 AC 230 ms
15,312 KB
testcase_37 AC 87 ms
15,076 KB
testcase_38 AC 95 ms
15,076 KB
testcase_39 AC 229 ms
15,556 KB
testcase_40 AC 109 ms
15,244 KB
testcase_41 AC 83 ms
15,232 KB
testcase_42 AC 73 ms
15,136 KB
testcase_43 AC 76 ms
15,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def main
  n = gets.to_i - 1
  c = gets.to_i
  v = gets.to_i
  s = gets.split.map { |val| val.to_i - 1 }.freeze
  t = gets.split.map { |val| val.to_i - 1 }.freeze
  y = gets.split.map(&:to_i).freeze
  m = gets.split.map(&:to_i).freeze
  dp = Array.new(n + 1) { Array.new(c + 1, Float::INFINITY) }
  dp[0][0] = 0

  [*0..(n + 1)].product([*0..(c + 1)]) do |cur, total|
    v.times do |i|
      next if cur != s[i] || c < total + y[i]

      dp[t[i]][total + y[i]] =
        [dp[t[i]][total + y[i]], dp[cur][total] + m[i]].min
    end
  end
  dp[n].min.infinite? ? -1 : dp[n].min
end

puts main
0