結果

問題 No.20 砂漠のオアシス
ユーザー 👑 obakyanobakyan
提出日時 2019-06-08 20:57:32
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 1,257 bytes
コンパイル時間 28 ms
コンパイル使用メモリ 5,120 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-15 20:01:29
合計ジャッジ時間 1,225 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 22 ms
5,376 KB
testcase_06 AC 15 ms
5,376 KB
testcase_07 AC 185 ms
13,184 KB
testcase_08 AC 45 ms
6,528 KB
testcase_09 AC 103 ms
9,216 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 9 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 13 ms
5,376 KB
testcase_19 AC 13 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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
0