結果
| 問題 |
No.286 Modulo Discount Store
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2019-07-07 00:41:33 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 19 ms / 2,000 ms |
| コード長 | 1,444 bytes |
| コンパイル時間 | 260 ms |
| コンパイル使用メモリ | 5,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 20:21:30 |
| 合計ジャッジ時間 | 1,509 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local tbl = {}
local function prepare(n, cost)
local tot = 1
local alltask = {}
local stagetask = {}
for i = 1, n do
tot = tot * 2
stagetask[i] = {}
end
for i = 1, tot - 1 do
alltask[i] = 150000
tbl[i] = 0
end
for i = 1, tot - 1 do
local ti = i
local cnt = 0
for j = 1, n do
if ti % 2 == 1 then
tbl[i] = tbl[i] + cost[j]
cnt = cnt + 1
ti = ti - 1
end
ti = ti / 2
end
table.insert(stagetask[cnt], i)
end
-- set first state
local tmp = 1
for i = 1, n do
alltask[tmp] = cost[i]
tmp = tmp * 2
end
return tot, alltask, stagetask
end
local function doall(n, alltask, stagetask, cost)
for stage = 1, n - 1 do
local stlen = #stagetask[stage]
for i_stagetask = 1, stlen do
local used = stagetask[stage][i_stagetask]
local mul = 1
local tmp = used
for j = 1, n do
if tmp % 2 == 0 then
alltask[used + mul] = mmi(alltask[used + mul], alltask[used] + mma(0, cost[j] - tbl[used] % 1000))
else
tmp = tmp - 1
end
tmp = tmp / 2
mul = mul * 2
end
end
end
end
local n = io.read("*n")
local cost = {}
for i = 1, n do
cost[i] = io.read("*n")
end
local tot, alltask, stagetask = prepare(n, cost)
doall(n, alltask, stagetask, cost)
print(alltask[tot - 1])