結果

問題 No.9 モンスターのレベル上げ
ユーザー S97323424S97323424
提出日時 2020-10-10 22:05:26
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 1,827 ms / 5,000 ms
コード長 1,675 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 4,672 KB
最終ジャッジ日時 2023-09-27 22:41:52
合計ジャッジ時間 14,593 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1,827 ms
4,380 KB
testcase_03 AC 1,385 ms
4,376 KB
testcase_04 AC 717 ms
4,380 KB
testcase_05 AC 501 ms
4,384 KB
testcase_06 AC 169 ms
4,380 KB
testcase_07 AC 34 ms
4,376 KB
testcase_08 AC 229 ms
4,376 KB
testcase_09 AC 1,716 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 739 ms
4,376 KB
testcase_12 AC 406 ms
4,376 KB
testcase_13 AC 688 ms
4,380 KB
testcase_14 AC 1,706 ms
4,376 KB
testcase_15 AC 1,581 ms
4,376 KB
testcase_16 AC 28 ms
4,376 KB
testcase_17 AC 1,004 ms
4,376 KB
testcase_18 AC 817 ms
4,380 KB
testcase_19 AC 110 ms
4,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local function meld(node1,node2)
    if not node1 then
        return node2
    elseif not node2 then
        return node1
    elseif node1[1]<node2[1] then
        node2[4]=node1[3]
        node1[3]=node2
        return node1
    else
        node1[4]=node2[3]
        node2[3]=node1
        return node2
    end
end

local function pairing(node,stack)
    if node and node[4] then
        return pairing(node[4][4],rawset(meld(node,node[4]),4,stack))
    else
        return stack,node
    end
end

local function meld_pairs(stack,node)
    if stack then
        return meld_pairs(stack[4],meld(stack,node))
    else
        return node
    end
end

local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=meld_pairs(pairing(self[1][3],false))
end

PairingHeap.new=function()
    return setmetatable({false},{__index=PairingHeap})
end

----------

local n=io.read("*n")
local a={}
for i=1,n do
    a[i]=io.read("*n")
end
local b={}
for i=1,n do
    b[i]=io.read("*n")
end

local min=10^20
for i=0,n-1 do
    local pq=PairingHeap:new()
    for j=1,n do
        local A={a[j],0}
        pq:push(A[1]*100000+A[2],A)
    end
    for j=1+i,n+i do
        local A=pq:top() pq:pop()
        A[1]=A[1]+math.floor(b[j%n+1]/2)
        A[2]=A[2]+1
        pq:push(A[1]*100000+A[2],A)
    end
    local max=0
    for j=1,n do
        local A=pq:top() pq:pop()
        max=math.max(A[2],max)
    end
    min=math.min(max,min)
end
print(string.format("%d",min))
0