結果

問題 No.1449 新プロランド
ユーザー 👑 obakyanobakyan
提出日時 2021-08-10 22:39:29
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 2,526 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 35,716 KB
最終ジャッジ日時 2024-06-06 11:09:46
合計ジャッジ時間 4,234 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 416 ms
35,684 KB
testcase_06 AC 187 ms
19,256 KB
testcase_07 AC 128 ms
19,292 KB
testcase_08 AC 382 ms
35,636 KB
testcase_09 AC 28 ms
6,944 KB
testcase_10 AC 170 ms
35,648 KB
testcase_11 AC 81 ms
35,712 KB
testcase_12 AC 313 ms
35,712 KB
testcase_13 AC 52 ms
6,940 KB
testcase_14 AC 100 ms
35,716 KB
testcase_15 AC 221 ms
19,368 KB
testcase_16 AC 64 ms
7,040 KB
testcase_17 AC 164 ms
19,164 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 26 ms
19,276 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 86 ms
19,224 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 160 ms
35,620 KB
testcase_24 AC 21 ms
6,944 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 407 ms
35,620 KB
testcase_28 AC 91 ms
7,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local pow2 = {1}
for i = 2, 28 do pow2[i] = pow2[i - 1] * 2 end
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = pow2[i]
    for j = 0, cnt - 1 do
      self.stage[cnt + j] = self.func(self.stage[(cnt + j) * 2], self.stage[(cnt + j) * 2 + 1])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {} -- use 1D Tree (stage[], not stage[][])
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
  end
  self.stagenum = stagenum
  for i = 1, mul * 2 - 1 do self.stage[i] = emptyvalue end
  for i = 1, n do self.stage[mul + i - 1] = i end
  self:updateAll()
end
SegTree.update = function(self, idx, force)
  idx = idx + pow2[self.stagenum] - 1
  for i = self.stagenum - 1, 1, -1 do
    local dst = mfl(idx / 2)
    local rem = dst * 4 + 1 - idx
    self.stage[dst] = self.func(self.stage[idx], self.stage[rem])
    if not force and self.stage[dst] ~= self.stage[idx] then break end
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local rn, m = io.read("*n", "*n")
local edge = {}
for i = 1, rn do
  edge[i] = {}
end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  edge[a][b], edge[b][a] = c, c
end
local d = {}
for i = 1, rn do
  d[i] = io.read("*n")
end
local lim = (rn - 1) * 100 + 1
local n = lim * rn

local inf = 1000000007
local len = {}
local asked = {}
for i = 1, n do
  len[i] = inf
  asked[i] = false
end
len[1] = 0
asked[n + 1] = true

local function mergefunc(x, y)
  if asked[x] then return y
  elseif asked[y] then return x
  else
    return len[x] < len[y] and x or y
  end
end

local st = SegTree.new(n, mergefunc, n + 1)

for i = 1, n do
  local src = st.stage[1]
  if asked[src] then break end
  if inf <= len[src] then break end
  asked[src] = true
  st:update(src, true)
  local w = mce(src / rn)
  local rawsrc = src - (w - 1) * rn
  local nxtlen = len[src] + d[rawsrc]
  w = w + d[rawsrc]
  for rawdst, c in pairs(edge[rawsrc]) do
    local dstlen = nxtlen + mfl(c / (w - 1))
    local dst = (w - 1) * rn + rawdst
    if dst <= n and dstlen < len[dst] then
      len[dst] = dstlen
      st:update(dst)
    end
  end
end
local ret = len[n]
for i = 1, lim do
  ret = mmi(ret, len[(i - 1) * rn + rn])
end
print(ret)
0