結果

問題 No.2100 [Cherry Alpha C] Two-way Steps
ユーザー 👑 obakyanobakyan
提出日時 2022-10-23 21:04:05
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 31 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 28,744 KB
最終ジャッジ日時 2023-09-15 06:35:30
合計ジャッジ時間 9,381 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,500 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 210 ms
18,808 KB
testcase_05 AC 166 ms
16,480 KB
testcase_06 AC 27 ms
6,132 KB
testcase_07 AC 34 ms
7,904 KB
testcase_08 AC 215 ms
24,516 KB
testcase_09 AC 148 ms
12,788 KB
testcase_10 AC 79 ms
5,488 KB
testcase_11 AC 145 ms
17,372 KB
testcase_12 AC 99 ms
10,252 KB
testcase_13 AC 125 ms
19,956 KB
testcase_14 AC 85 ms
7,940 KB
testcase_15 AC 132 ms
19,552 KB
testcase_16 AC 94 ms
8,524 KB
testcase_17 AC 80 ms
17,516 KB
testcase_18 AC 125 ms
20,012 KB
testcase_19 AC 242 ms
24,656 KB
testcase_20 AC 46 ms
7,832 KB
testcase_21 AC 97 ms
10,952 KB
testcase_22 AC 93 ms
8,248 KB
testcase_23 AC 194 ms
21,884 KB
testcase_24 AC 282 ms
27,036 KB
testcase_25 AC 274 ms
27,172 KB
testcase_26 AC 279 ms
27,248 KB
testcase_27 AC 276 ms
27,100 KB
testcase_28 AC 282 ms
27,248 KB
testcase_29 AC 274 ms
27,192 KB
testcase_30 AC 289 ms
27,156 KB
testcase_31 AC 275 ms
27,260 KB
testcase_32 AC 280 ms
27,240 KB
testcase_33 AC 286 ms
27,096 KB
testcase_34 AC 134 ms
9,516 KB
testcase_35 AC 119 ms
8,276 KB
testcase_36 AC 120 ms
8,240 KB
testcase_37 AC 112 ms
6,960 KB
testcase_38 AC 134 ms
8,968 KB
testcase_39 AC 106 ms
7,524 KB
testcase_40 AC 104 ms
7,468 KB
testcase_41 AC 105 ms
7,448 KB
testcase_42 AC 105 ms
7,452 KB
testcase_43 AC 106 ms
7,488 KB
testcase_44 AC 149 ms
28,644 KB
testcase_45 AC 150 ms
28,744 KB
testcase_46 AC 150 ms
28,668 KB
testcase_47 AC 148 ms
28,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n, m = io.read("*n", "*n")
local h = {}
local edge = {}
local invedge = {}
for i = 1, n do
  h[i] = io.read("*n")
  edge[i] = {}
  invedge[i] = {}
end
for i = 1, m do
  local x, y = io.read("*n", "*n")
  table.insert(edge[x], y)
  table.insert(invedge[y], x)
end
local function solve()
  local upped = {0}
  local downed = {0}
  for i = 2, n do
    upped[i], downed[i] = -1, -1
  end
  for i = 1, n - 1 do
    for j = 1, #edge[i] do
      local dst = edge[i][j]
      if h[i] < h[dst] and 0 <= downed[i] then
        upped[dst] = mma(upped[dst], downed[i] + h[dst] - h[i])
      end
      if h[dst] < h[i] and 0 <= upped[i] then
        downed[dst] = mma(downed[dst], upped[i])
      end
      if h[dst] < h[i] and 0 <= downed[i] then
        downed[dst] = mma(downed[dst], downed[i])
      end
    end
  end
  print(mma(downed[n], upped[n]))
end
solve()
for i = 1, n do
  edge[i] = {}
  local z = n + 1 - i
  if i < z then
    h[i], h[z] = h[z], h[i]
  end
end
for i = 1, n do
  for j = 1, #invedge[i] do
    local dst = invedge[i][j]
    table.insert(edge[n + 1 - i], n + 1 - dst)
  end
end

solve()
0