結果
問題 | No.210 探し物はどこですか? |
ユーザー |
👑 |
提出日時 | 2021-08-12 21:54:04 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 1,516 ms / 2,000 ms |
コード長 | 1,808 bytes |
コンパイル時間 | 90 ms |
コンパイル使用メモリ | 5,120 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-02 03:13:04 |
合計ジャッジ時間 | 72,389 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
local bls, brs = bit.lshift, bit.rshiftlocal Heapq = {}Heapq.create = function(self, lt)self.lt = ltself.cnt = 0self.t = {}endHeapq.push = function(self, v)local hqlt = self.ltlocal hqt = self.tlocal c = self.cnt + 1self.cnt = chqt[c] = vwhile 1 < c dolocal p = brs(c, 1)if hqlt(hqt[c], hqt[p]) thenhqt[c], hqt[p] = hqt[p], hqt[c]c = pelsebreakendendendHeapq.pop = function(self)local hqlt = self.ltlocal hqt = self.tlocal ret = hqt[1]local c = self.cnthqt[1] = hqt[c]c = c - 1self.cnt = clocal p = 1while true dolocal d1, d2 = p * 2, p * 2 + 1if c < d1 then breakelseif c < d2 thenif hqlt(hqt[d1], hqt[p]) thenhqt[d1], hqt[p] = hqt[p], hqt[d1]endbreakelseif hqlt(hqt[d1], hqt[d2]) thenif hqlt(hqt[d1], hqt[p]) thenhqt[d1], hqt[p] = hqt[p], hqt[d1]p = d1else breakendelseif hqlt(hqt[d2], hqt[p]) thenhqt[d2], hqt[p] = hqt[p], hqt[d2]p = d2else breakendendendendreturn retendHeapq.new = function(lt)local obj = {}setmetatable(obj, {__index = Heapq})obj:create(lt)return objendlocal n = io.read("*n")local p, q = {}, {}for i = 1, n dop[i] = io.read("*n") / 1000.0endfor i = 1, n doq[i] = io.read("*n") / 100.0endlocal chance = {}for i = 1, n dochance[i] = p[i] * q[i]endlocal hq = Heapq.new(function(x, y) return chance[x] > chance[y] end)for i = 1, n dohq:push(i)endlocal ret = 0local i = 0while os.clock() < 1.5 doi = i + 1local idx = hq:pop()ret = ret + i * chance[idx]chance[idx] = chance[idx] * (1 - q[idx])hq:push(idx)endprint(string.format("%.10f", ret))