結果
問題 | No.340 雪の足跡 |
ユーザー | 👑 obakyan |
提出日時 | 2020-04-25 23:38:23 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 507 ms / 1,000 ms |
コード長 | 2,578 bytes |
コンパイル時間 | 345 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 44,544 KB |
最終ジャッジ日時 | 2024-11-08 02:14:40 |
合計ジャッジ時間 | 8,794 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 7 ms
5,248 KB |
testcase_12 | AC | 6 ms
5,248 KB |
testcase_13 | AC | 8 ms
5,248 KB |
testcase_14 | AC | 30 ms
7,552 KB |
testcase_15 | AC | 35 ms
8,320 KB |
testcase_16 | AC | 25 ms
5,248 KB |
testcase_17 | AC | 43 ms
8,448 KB |
testcase_18 | AC | 37 ms
8,448 KB |
testcase_19 | AC | 43 ms
8,448 KB |
testcase_20 | AC | 319 ms
38,528 KB |
testcase_21 | AC | 199 ms
5,248 KB |
testcase_22 | AC | 48 ms
36,224 KB |
testcase_23 | AC | 390 ms
44,544 KB |
testcase_24 | AC | 279 ms
36,352 KB |
testcase_25 | AC | 301 ms
37,504 KB |
testcase_26 | AC | 52 ms
5,248 KB |
testcase_27 | AC | 15 ms
5,248 KB |
testcase_28 | AC | 48 ms
5,376 KB |
testcase_29 | AC | 415 ms
40,832 KB |
testcase_30 | AC | 283 ms
26,752 KB |
testcase_31 | AC | 437 ms
43,648 KB |
testcase_32 | AC | 503 ms
44,416 KB |
testcase_33 | AC | 406 ms
44,544 KB |
testcase_34 | AC | 507 ms
44,544 KB |
testcase_35 | AC | 369 ms
44,416 KB |
testcase_36 | AC | 365 ms
44,416 KB |
ソースコード
local mfl, mce = math.floor, math.ceil local w, h, nq = io.read("*n", "*n", "*n") local rows = {} for i = 1, h do rows[i] = {} for j = 1, w do rows[i][j] = 0 end end local cols = {} for i = 1, w do cols[i] = {} for j = 1, h do cols[i][j] = 0 end end local function getrowcol(idx) local c = idx % w + 1 local r = mfl(idx / w) + 1 return r, c end for i = 1, nq do local m = io.read("*n") local src = io.read("*n") local src_row, src_col = getrowcol(src) for j = 1, m do local dst = io.read("*n") local dst_row, dst_col = getrowcol(dst) if src_row == dst_row then if src_col < dst_col then rows[src_row][src_col] = rows[src_row][src_col] + 1 rows[src_row][dst_col] = rows[src_row][dst_col] - 1 else rows[src_row][src_col] = rows[src_row][src_col] - 1 rows[src_row][dst_col] = rows[src_row][dst_col] + 1 end else if src_row < dst_row then cols[src_col][src_row] = cols[src_col][src_row] + 1 cols[src_col][dst_row] = cols[src_col][dst_row] - 1 else cols[src_col][src_row] = cols[src_col][src_row] - 1 cols[src_col][dst_row] = cols[src_col][dst_row] + 1 end end src_row, src_col = dst_row, dst_col end end for i = 1, h do for j = 2, w do rows[i][j] = rows[i][j] + rows[i][j - 1] end end for i = 1, w do for j = 2, h do cols[i][j] = cols[i][j] + cols[i][j - 1] end end local inf = 1000000007 local len = {} local taskstate = {} for i = 1, h * w do taskstate[i] = false len[i] = inf end len[1] = 0 local tasks = {} local tasknum = 0 local done = 0 local tasklim = h * w local function addtask(idx) if not taskstate[idx] then taskstate[idx] = true tasknum = tasknum + 1 local taskidx = tasknum % tasklim if taskidx == 0 then taskidx = tasklim end tasks[taskidx] = idx end end local function walk(src, dst) if len[src] + 1 < len[dst] then len[dst] = len[src] + 1 addtask(dst) end end addtask(1) while done < tasknum do done = done + 1 local taskidx = done % tasklim if taskidx == 0 then taskidx = tasklim end local idx = tasks[taskidx] taskstate[idx] = false local r, c = getrowcol(idx - 1) if w < idx and 0 < cols[c][r - 1] then walk(idx, idx - w) end if idx <= (h - 1) * w and 0 < cols[c][r] then walk(idx, idx + w) end if 1 < w then if idx % w ~= 0 and 0 < rows[r][c] then walk(idx, idx + 1) end if idx % w ~= 1 and 0 < rows[r][c - 1] then walk(idx, idx - 1) end end end print(inf <= len[h * w] and "Odekakedekinai.." or len[h * w])