結果
問題 | No.20 砂漠のオアシス |
ユーザー | 👑 obakyan |
提出日時 | 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 |
ソースコード
local mfl = math.floorlocal n, v, ox, oy = io.read("*n", "*n", "*n", "*n")local oidx = (oy - 1) * n + oxlocal map = {}for i = 1, n * n domap[i] = io.read("*n")endlocal function walk(src, dst, life, tasks)if life[dst] < life[src] - map[dst] thentable.insert(tasks, dst)life[dst] = life[src] - map[dst]endendlocal function dig(srcidx, srcval, dstidx)local life = {}for i = 1, n * n do life[i] = 0 endlife[srcidx] = srcvallocal tasks = {srcidx}local tasknum, done = 1, 0while done < tasknum dodone = done + 1local curidx = tasks[done]if curidx % n ~= 0 then walk(curidx, curidx + 1, life, tasks) endif curidx % n ~= 1 then walk(curidx, curidx - 1, life, tasks) endif n < curidx then walk(curidx, curidx - n, life, tasks) endif curidx <= n * n - n then walk(curidx, curidx + n, life, tasks) endtasknum = #tasksendreturn life[dstidx]endlocal straight = dig(1, v, n * n)if 0 < straight thenprint("YES")elselocal f = falseif 0 < oidx thenlocal tooasis = dig(1, v, oidx)if 0 < tooasis thenlocal toend = dig(oidx, tooasis * 2, n * n)if 0 < toend thenprint("YES") f = trueendendendif not f then print("NO") endend