結果
| 問題 |
No.943 取り調べ
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-06-10 21:50:09 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 597 ms / 1,206 ms |
| コード長 | 1,817 bytes |
| コンパイル時間 | 346 ms |
| コンパイル使用メモリ | 6,816 KB |
| 実行使用メモリ | 13,312 KB |
| 最終ジャッジ日時 | 2024-11-30 08:56:19 |
| 合計ジャッジ時間 | 4,745 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local function bdp_prepare(n, t, a)
local tot = bls(1, n)
local alltask = {}
local stagetask = {}
for i = 1, n do
stagetask[i] = {}
end
for i = 1, tot - 1 do
alltask[i] = 1000000007
end
for i = 1, tot - 1 do
local ti = i
local cnt = 0
for j = 1, n do
if ti % 2 == 1 then
cnt = cnt + 1
end
ti = brs(ti, 1)
end
table.insert(stagetask[cnt], i)
end
local tmp = 1
for i = 1, n do
if #t[i] == 0 then
alltask[tmp] = 0
else
alltask[tmp] = a[i]
end
tmp = tmp * 2
end
return tot, alltask, stagetask
end
local function bdp_doall(n, alltask, stagetask, t, a)
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
local b = {}
local c = {}
for j = 1, n do
if tmp % 2 == 0 then
table.insert(c, j)
else
b[j] = true
end
tmp = brs(tmp, 1)
mul = mul * 2
end
for j = 1, #c do
local tgt = c[j]
local cost = 0
for k = 1, #t[tgt] do
if not b[ t[tgt][k] ] then
cost = a[tgt] break
end
end
local dst = used + bls(1, tgt - 1)
alltask[dst] = mmi(alltask[dst], alltask[used] + cost)
end
end
end
end
local n = io.read("*n")
local t = {}
for i = 1, n do
t[i] = {}
for j = 1, n do
local tij = io.read("*n")
if tij == 1 then table.insert(t[i], j) end
end
end
local a = {}
for i = 1, n do
a[i] = io.read("*n")
end
local tot, alltask, stagetask = bdp_prepare(n, t, a)
bdp_doall(n, alltask, stagetask, t, a)
print(alltask[tot - 1])