結果
問題 | No.1708 Quality of Contest |
ユーザー | 👑 obakyan |
提出日時 | 2022-01-22 21:53:09 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 482 ms / 2,000 ms |
コード長 | 2,272 bytes |
コンパイル時間 | 175 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 51,584 KB |
最終ジャッジ日時 | 2024-05-05 22:22:31 |
合計ジャッジ時間 | 8,432 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 10 ms
5,376 KB |
testcase_04 | AC | 9 ms
5,376 KB |
testcase_05 | AC | 9 ms
5,376 KB |
testcase_06 | AC | 8 ms
5,376 KB |
testcase_07 | AC | 7 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 369 ms
51,584 KB |
testcase_10 | AC | 400 ms
47,104 KB |
testcase_11 | AC | 345 ms
28,800 KB |
testcase_12 | AC | 377 ms
30,552 KB |
testcase_13 | AC | 318 ms
25,216 KB |
testcase_14 | AC | 375 ms
31,656 KB |
testcase_15 | AC | 460 ms
48,768 KB |
testcase_16 | AC | 482 ms
47,104 KB |
testcase_17 | AC | 390 ms
32,768 KB |
testcase_18 | AC | 397 ms
33,408 KB |
testcase_19 | AC | 424 ms
40,324 KB |
testcase_20 | AC | 388 ms
32,384 KB |
testcase_21 | AC | 422 ms
33,792 KB |
testcase_22 | AC | 384 ms
31,660 KB |
testcase_23 | AC | 453 ms
47,616 KB |
testcase_24 | AC | 305 ms
19,584 KB |
testcase_25 | AC | 295 ms
19,800 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.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, m, x = io.read("*n", "*n", "*n") local a, b = {}, {} for i = 1, n do a[i], b[i] = io.read("*n", "*n") end local t = {} local pos = {} for i = 1, m do t[i] = {} pos[i] = 1 end for i = 1, n do local ai, bi = a[i], b[i] table.insert(t[bi], ai) end local v = {} for i = 1, m do table.sort(t[i], function(p, q) return p > q end) if 0 < #t[i] then v[i] = x + t[i][1] else v[i] = 0 end end local score = {} local hq = Heapq.new(function(p, q) return v[p] > v[q] end) for i = 1, m do hq:push(i) end for i = 1, n do local idx = hq:pop() score[i] = v[idx] pos[idx] = pos[idx] + 1 if pos[idx] <= #t[idx] then v[idx] = t[idx][pos[idx]] else v[idx] = 0 end hq:push(idx) end for i = 2, n do score[i] = score[i] + score[i - 1] end local ret = 0LL local k = io.read("*n") local c = {} for i = 1, k do c[i] = io.read("*n") local ci = c[i] if 0 < ci then ret = ret + score[ci] end end ret = tostring(1LL * ret):gsub("LL", "") print(ret)