結果

問題 No.1 道のショートカット
ユーザー 👑 obakyanobakyan
提出日時 2019-09-20 21:24:50
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,625 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 13:37:47
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 5 ms
4,380 KB
testcase_11 AC 8 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 12 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 7 ms
4,376 KB
testcase_33 AC 4 ms
4,380 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n, c, v = io.read("*n", "*n", "*n")
local s, t, y = {}, {}, {}
local edge = {}
for i = 1, n do edge[i] = {} end
for i = 1, v do s[i] = io.read("*n") end
for i = 1, v do t[i] = io.read("*n") end
for i = 1, v do y[i] = io.read("*n") end
for i = 1, v do
  local m = io.read("*n")
  if not edge[s[i]][t[i]] then
    edge[s[i]][t[i]] = {}
  end
  table.insert(edge[s[i]][t[i]], {y[i], m})
end

local len = {}
local taskstate = {}
local inf = 1000000000
for i = 1, n * c do
  len[i] = inf
  taskstate[i] = false
end
local tasks = {}
local tasknum = 0
local done = 0
for dst, y_ms in pairs(edge[1]) do
  for _u, y_m in pairs(y_ms) do
    local idx = (y_m[1] - 1) * n + dst
    len[idx] = y_m[2]
    if dst < n then
      table.insert(tasks, idx)
      tasknum = tasknum + 1
      taskstate[idx] = true
    end
  end
end
local mfl, mmi = math.floor, math.min
while done < tasknum do
  done = done + 1
  local idx = tasks[done]
  taskstate[idx] = false
  -- src ~= n
  local src = idx % n
  local yen = 1 + mfl((idx - src) / n)
  for dst, y_ms in pairs(edge[src]) do
    for _u, y_m in pairs(y_ms) do
      local dst_idx = (yen + y_m[1] - 1) * n + dst
      if dst_idx <= n * c then
        if len[idx] + y_m[2] < len[dst_idx] then
          len[dst_idx] = len[idx] + y_m[2]
          if dst < n and not taskstate[dst_idx] then
            table.insert(tasks, dst_idx)
            tasknum = tasknum + 1
            taskstate[dst_idx] = true
          end
        end
      end
    end
  end
end
local minval = inf
for i = 1, c do
  minval = mmi(minval, len[i * n])
end
if minval == inf then
  print(-1)
else
  print(minval)
end
0