結果

問題 No.1995 CHIKA Road
ユーザー simansiman
提出日時 2022-07-03 08:30:27
言語 Ruby
(3.3.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 11,364 KB
実行使用メモリ 43,460 KB
最終ジャッジ日時 2023-08-19 06:51:41
合計ジャッジ時間 13,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
15,232 KB
testcase_01 AC 76 ms
15,336 KB
testcase_02 AC 74 ms
15,136 KB
testcase_03 AC 82 ms
15,132 KB
testcase_04 AC 73 ms
15,164 KB
testcase_05 AC 69 ms
15,268 KB
testcase_06 AC 91 ms
16,744 KB
testcase_07 AC 155 ms
20,916 KB
testcase_08 AC 70 ms
15,024 KB
testcase_09 AC 69 ms
15,156 KB
testcase_10 AC 223 ms
20,316 KB
testcase_11 AC 531 ms
43,460 KB
testcase_12 AC 366 ms
34,172 KB
testcase_13 AC 201 ms
27,468 KB
testcase_14 AC 213 ms
28,308 KB
testcase_15 AC 455 ms
42,060 KB
testcase_16 AC 110 ms
17,756 KB
testcase_17 AC 268 ms
27,696 KB
testcase_18 AC 393 ms
32,008 KB
testcase_19 AC 399 ms
31,380 KB
testcase_20 AC 240 ms
26,456 KB
testcase_21 AC 219 ms
22,852 KB
testcase_22 AC 374 ms
31,176 KB
testcase_23 AC 169 ms
20,920 KB
testcase_24 AC 336 ms
30,632 KB
testcase_25 AC 119 ms
17,988 KB
testcase_26 AC 174 ms
21,528 KB
testcase_27 AC 323 ms
29,980 KB
testcase_28 AC 223 ms
22,972 KB
testcase_29 AC 382 ms
31,544 KB
testcase_30 AC 117 ms
18,388 KB
testcase_31 AC 92 ms
16,736 KB
testcase_32 AC 133 ms
18,672 KB
testcase_33 AC 315 ms
30,140 KB
testcase_34 AC 95 ms
16,860 KB
testcase_35 AC 180 ms
21,304 KB
testcase_36 AC 198 ms
22,108 KB
testcase_37 AC 389 ms
31,544 KB
testcase_38 AC 275 ms
28,364 KB
testcase_39 AC 92 ms
16,612 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, M = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

P = []

M.times do
  a, b = gets.split.map(&:to_i)

  E[a] << b
  P << a
  P << b
end

P.unshift(1)
P.push(N)
P.uniq!
P.sort!
L = P.size
dp = Array.new(L, Float::INFINITY)
dp[0] = 0
I = Hash.new

P.each_with_index do |pos, idx|
  I[pos] = idx
end

(L - 1).times do |i|
  a = P[i]
  n_pos = P[i + 1]
  dist = 2 * (n_pos - a)

  dp[i + 1] = dp[i] + dist if dp[i] + dist < dp[i + 1]

  E[a].each do |u|
    idx = I[u]
    b = P[idx]
    dist = 2 * b - 2 * a - 1

    dp[idx] = dp[i] + dist if dp[i] + dist < dp[idx]
  end
end

puts dp.last
0