結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2019-04-29 18:42:14 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,506 bytes |
| コンパイル時間 | 415 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:18:04 |
| 合計ジャッジ時間 | 989 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
local ior = io.input()
local h, w = ior:read("*n", "*n")
local sh, sw, gh, gw = ior:read("*n", "*n", "*n", "*n", "*l")
local str = ""
local map = {}
local state = {}
local function getindex(xh, xw)
return (xh - 1) * w + xw
end
local cue = {getindex(sh, sw)}
state[getindex(sh, sw)] = true
local tasks, done = 1, 0
local function walk(src, dst)
if (math.abs(map[src] - map[dst]) <= 1) then
if(not state[dst]) then
state[dst] = true
tasks = tasks + 1
table.insert(cue, dst)
end
end
end
local function ladder(src, mid, dst)
if(map[src] == map[dst] and map[mid] < map[src]) then
if(not state[dst]) then
state[dst] = true
tasks = tasks + 1
table.insert(cue, dst)
end
end
end
for i = 1, h do
str = ior:read()
for j = 1, w do
local tmp = tonumber(str:sub(j, j))
local tmp2 = getindex(i, j)
map[tmp2] = tmp
state[tmp2] = false
end
end
while(done < tasks) do
done = done + 1
local idx = cue[done]
if(w < idx) then walk(idx, idx - w) end
if(idx <= (h - 1) * w) then walk(idx, idx + w) end
if(idx % w ~= 0) then walk(idx, idx + 1) end
if(idx % w ~= 1) then walk(idx, idx - 1) end
if(w * 2 < idx) then ladder(idx, idx - w, idx - 2 * w) end
if(idx <= (h - 2) * w) then ladder(idx, idx + w, idx + 2 * w) end
if(idx % w ~= 0 and idx % w ~= (w - 1)) then ladder(idx, idx + 1, idx + 2) end
if(idx % w ~= 1 and idx % w ~= 2) then ladder(idx, idx - 1, idx - 2) end
end
print(state[getindex(gh, gw)] and "YES" or "NO")