結果

問題 No.20 砂漠のオアシス
ユーザー 👑 obakyanobakyan
提出日時 2019-06-08 20:57:32
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 1,257 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 6,820 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-10-05 23:53:25
合計ジャッジ時間 1,330 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

local mfl = math.floor
local n, v, ox, oy = io.read("*n", "*n", "*n", "*n")
local oidx = (oy - 1) * n + ox
local map = {}
for i = 1, n * n do
map[i] = io.read("*n")
end
local function walk(src, dst, life, tasks)
if life[dst] < life[src] - map[dst] then
table.insert(tasks, dst)
life[dst] = life[src] - map[dst]
end
end
local function dig(srcidx, srcval, dstidx)
local life = {}
for i = 1, n * n do life[i] = 0 end
life[srcidx] = srcval
local tasks = {srcidx}
local tasknum, done = 1, 0
while done < tasknum do
done = done + 1
local curidx = tasks[done]
if curidx % n ~= 0 then walk(curidx, curidx + 1, life, tasks) end
if curidx % n ~= 1 then walk(curidx, curidx - 1, life, tasks) end
if n < curidx then walk(curidx, curidx - n, life, tasks) end
if curidx <= n * n - n then walk(curidx, curidx + n, life, tasks) end
tasknum = #tasks
end
return life[dstidx]
end
local straight = dig(1, v, n * n)
if 0 < straight then
print("YES")
else
local f = false
if 0 < oidx then
local tooasis = dig(1, v, oidx)
if 0 < tooasis then
local toend = dig(oidx, tooasis * 2, n * n)
if 0 < toend then
print("YES") f = true
end
end
end
if not f then print("NO") end
end
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0