結果
問題 | No.1638 Robot Maze |
ユーザー | 👑 obakyan |
提出日時 | 2021-08-06 21:47:13 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,007 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-17 01:40:53 |
合計ジャッジ時間 | 1,572 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 14 ms
6,944 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 3 ms
6,944 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | AC | 3 ms
6,944 KB |
testcase_47 | AC | 3 ms
6,940 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | AC | 3 ms
6,940 KB |
ソースコード
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 h, w = io.read("*n", "*n") assert(1 < h and 1 < w) local c_up, c_down, c_right, c_left = io.read("*n", "*n", "*n", "*n") local klim, p = io.read("*n", "*n") local xs, ys = io.read("*n", "*n") local xt, yt = io.read("*n", "*n", "*l") local map = {} for i = 1, h do local s = io.read() map[i] = {} for j = 1, w do map[i][j] = s:sub(j, j) end end local n = h * w local inf = klim + 1 local len = {} local asked = {} for i = 1, n do len[i] = inf asked[i] = false end local spos = (xs - 1) * w + ys 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) local function walk(src, dst) local dst_row = mce(dst / w) local dst_col = dst - (dst_row - 1) * w local cost = 0 if src + 1 == dst then cost = c_right elseif src - 1 == dst then cost = c_left elseif src + w == dst then cost = c_down elseif src - w == dst then cost = c_up else assert(false) end if map[dst_row][dst_col] == "#" then print("DST", dst) return end if map[dst_row][dst_col] == "@" then cost = cost + p end if len[src] + cost < len[dst] then len[dst] = len[src] + cost st:update(dst) end end 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) if src % w ~= 1 then walk(src, src - 1) end if src % w ~= 0 then walk(src, src + 1) end if w < src then walk(src, src - w) end if src <= (h - 1) * w then walk(src, src + w) end end local tpos = (xt - 1) * w + yt print(len[tpos] <= klim and "Yes" or "No")