結果

問題 No.1 道のショートカット
ユーザー 👑 obakyanobakyan
提出日時 2019-09-20 21:08:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 5,288 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 13:37:45
合計ジャッジ時間 1,583 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 3 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,376 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 1 ms
4,380 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
4,380 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")
  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_m in pairs(edge[1]) 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
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_m in pairs(edge[src]) 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
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