結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー tomeruntomerun
提出日時 2022-10-14 21:38:54
言語 Crystal
(1.10.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 898 bytes
コンパイル時間 17,482 ms
コンパイル使用メモリ 257,752 KB
実行使用メモリ 28,432 KB
最終ジャッジ日時 2023-09-08 20:31:11
合計ジャッジ時間 22,956 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,480 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 2 ms
4,500 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 88 ms
22,348 KB
testcase_05 AC 68 ms
20,072 KB
testcase_06 AC 14 ms
7,868 KB
testcase_07 AC 17 ms
8,536 KB
testcase_08 AC 76 ms
23,264 KB
testcase_09 AC 80 ms
19,236 KB
testcase_10 AC 55 ms
16,776 KB
testcase_11 AC 67 ms
21,940 KB
testcase_12 AC 52 ms
15,928 KB
testcase_13 AC 46 ms
18,912 KB
testcase_14 AC 52 ms
14,368 KB
testcase_15 AC 47 ms
15,172 KB
testcase_16 AC 57 ms
18,264 KB
testcase_17 AC 26 ms
11,852 KB
testcase_18 AC 46 ms
17,944 KB
testcase_19 AC 98 ms
23,876 KB
testcase_20 AC 23 ms
9,644 KB
testcase_21 AC 48 ms
14,836 KB
testcase_22 AC 53 ms
14,576 KB
testcase_23 AC 74 ms
21,728 KB
testcase_24 AC 104 ms
27,008 KB
testcase_25 AC 107 ms
26,952 KB
testcase_26 AC 108 ms
26,888 KB
testcase_27 AC 110 ms
27,040 KB
testcase_28 AC 104 ms
27,020 KB
testcase_29 AC 103 ms
27,136 KB
testcase_30 AC 103 ms
28,432 KB
testcase_31 AC 105 ms
28,220 KB
testcase_32 AC 101 ms
27,056 KB
testcase_33 AC 106 ms
26,872 KB
testcase_34 AC 84 ms
22,200 KB
testcase_35 AC 80 ms
24,340 KB
testcase_36 AC 80 ms
24,416 KB
testcase_37 AC 76 ms
20,632 KB
testcase_38 AC 80 ms
22,164 KB
testcase_39 AC 77 ms
20,668 KB
testcase_40 AC 77 ms
20,636 KB
testcase_41 AC 76 ms
20,612 KB
testcase_42 AC 76 ms
20,536 KB
testcase_43 AC 76 ms
20,864 KB
testcase_44 AC 71 ms
18,936 KB
testcase_45 AC 71 ms
19,656 KB
testcase_46 AC 72 ms
24,108 KB
testcase_47 AC 71 ms
23,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = read_line.split.map(&.to_i)
h = read_line.split.map(&.to_i64)
es = Array.new(m) { read_line.split.map { |v| v.to_i - 1 } }

puts solve(h, es)
h.reverse!
es.map! { |e| [n - 1 - e[1], n - 1 - e[0]] }
puts solve(h, es)

def solve(h, es)
  n = h.size
  g = Array.new(n) { [] of Int32 }
  es.each do |e|
    g[e[0]] << e[1]
  end
  dp = Array.new(2) { Array.new(n, -1i64) }
  dp[0][0] = 0
  n.times do |i|
    h0 = h[i]
    if dp[0][i] != -1
      g[i].each do |adj|
        h1 = h[adj]
        if h0 < h1
          dp[1][adj] = {dp[1][adj], dp[0][i] + h1 - h0}.max
        else
          dp[0][adj] = {dp[0][adj], dp[0][i]}.max
        end
      end
    end
    if dp[1][i] != -1
      g[i].each do |adj|
        h1 = h[adj]
        if h0 < h1
          #
        else
          dp[0][adj] = {dp[0][adj], dp[1][i]}.max
        end
      end
    end
  end
  return {dp[0][-1], dp[1][-1]}.max
end
0