結果
問題 | No.1868 Teleporting Cyanmond |
ユーザー | 👑 obakyan |
提出日時 | 2022-03-13 23:11:31 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 119 ms / 2,000 ms |
コード長 | 2,462 bytes |
コンパイル時間 | 41 ms |
コンパイル使用メモリ | 5,152 KB |
実行使用メモリ | 14,020 KB |
最終ジャッジ日時 | 2023-10-19 10:40:04 |
合計ジャッジ時間 | 3,371 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 1 ms
4,348 KB |
testcase_03 | AC | 118 ms
13,176 KB |
testcase_04 | AC | 73 ms
10,084 KB |
testcase_05 | AC | 17 ms
4,348 KB |
testcase_06 | AC | 24 ms
4,624 KB |
testcase_07 | AC | 67 ms
8,220 KB |
testcase_08 | AC | 35 ms
5,812 KB |
testcase_09 | AC | 50 ms
7,160 KB |
testcase_10 | AC | 119 ms
12,540 KB |
testcase_11 | AC | 7 ms
4,348 KB |
testcase_12 | AC | 51 ms
6,232 KB |
testcase_13 | AC | 56 ms
7,632 KB |
testcase_14 | AC | 72 ms
12,028 KB |
testcase_15 | AC | 49 ms
8,676 KB |
testcase_16 | AC | 16 ms
4,348 KB |
testcase_17 | AC | 22 ms
4,756 KB |
testcase_18 | AC | 112 ms
14,020 KB |
testcase_19 | AC | 72 ms
12,820 KB |
testcase_20 | AC | 75 ms
13,084 KB |
testcase_21 | AC | 84 ms
12,832 KB |
testcase_22 | AC | 85 ms
13,096 KB |
testcase_23 | AC | 65 ms
13,084 KB |
testcase_24 | AC | 64 ms
13,084 KB |
testcase_25 | AC | 64 ms
13,084 KB |
testcase_26 | AC | 64 ms
13,084 KB |
testcase_27 | AC | 63 ms
13,084 KB |
ソースコード
local bls, brs = bit.lshift, bit.rshift local Heapq = {} Heapq.create = function(self, lt) self.lt = lt self.cnt = 0 self.t = {} end Heapq.push = function(self, v) local hqlt = self.lt local hqt = self.t local c = self.cnt + 1 self.cnt = c hqt[c] = v while 1 < c do local p = brs(c, 1) if hqlt(hqt[c], hqt[p]) then hqt[c], hqt[p] = hqt[p], hqt[c] c = p else break end end end Heapq.empty = function(self) return self.cnt == 0 end Heapq.top = function(self) return self.t[1] end Heapq.pop = function(self) local hqlt = self.lt local hqt = self.t local ret = hqt[1] local c = self.cnt hqt[1] = hqt[c] c = c - 1 self.cnt = c local p = 1 while true do local d1, d2 = p * 2, p * 2 + 1 if c < d1 then break elseif c < d2 then if hqlt(hqt[d1], hqt[p]) then hqt[d1], hqt[p] = hqt[p], hqt[d1] end break else if hqlt(hqt[d1], hqt[d2]) then if hqlt(hqt[d1], hqt[p]) then hqt[d1], hqt[p] = hqt[p], hqt[d1] p = d1 else break end else if hqlt(hqt[d2], hqt[p]) then hqt[d2], hqt[p] = hqt[p], hqt[d2] p = d2 else break end end end end return ret end Heapq.new = function(lt) local obj = {} setmetatable(obj, {__index = Heapq}) obj:create(lt) return obj end local n = io.read("*n") local hqadd = Heapq.new(function(a, b) return a < b end) local hqrm = Heapq.new(function(a, b) return a < b end) local rmtasks = {} for i = 1, n + 1 do rmtasks[i] = {} end for i = 1, n - 1 do local right = io.read("*n") for j = 1, #rmtasks[i] do hqrm:push(rmtasks[i][j]) end while true do local cont = false if not hqadd:empty() and not hqrm:empty() then if hqadd:top() == hqrm:top() then hqadd:pop() hqrm:pop() cont = true end end if not cont then break end end local cur = hqadd:empty() and 0 or hqadd:top() local nxt = cur + 1 hqadd:push(nxt) table.insert(rmtasks[right + 1], nxt) end do local i = n for j = 1, #rmtasks[i] do hqrm:push(rmtasks[i][j]) end while true do local cont = false if not hqadd:empty() and not hqrm:empty() then if hqadd:top() == hqrm:top() then hqadd:pop() hqrm:pop() cont = true end end if not cont then break end end local cur = hqadd:empty() and 0 or hqadd:top() print(cur) end