結果

問題 No.943 取り調べ
ユーザー 👑 obakyanobakyan
提出日時 2021-06-10 21:50:09
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 635 ms / 1,206 ms
コード長 1,817 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 5,380 KB
実行使用メモリ 13,092 KB
最終ジャッジ日時 2023-08-20 08:00:13
合計ジャッジ時間 5,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 635 ms
12,964 KB
testcase_05 AC 615 ms
12,928 KB
testcase_06 AC 610 ms
12,996 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 635 ms
13,028 KB
testcase_09 AC 141 ms
5,144 KB
testcase_10 AC 137 ms
5,104 KB
testcase_11 AC 69 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 138 ms
5,152 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 140 ms
5,296 KB
testcase_23 AC 630 ms
13,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0