結果

問題 No.90 品物の並び替え
ユーザー 👑 obakyanobakyan
提出日時 2019-05-05 21:57:09
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 649 ms / 5,000 ms
コード長 1,069 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 5,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 10:34:57
合計ジャッジ時間 2,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 82 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 11 ms
4,376 KB
testcase_05 AC 64 ms
4,380 KB
testcase_06 AC 83 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 649 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

local tot = 1
for i = 2, n do tot = tot * i end

local function getpattern(n, patall, idx)
  local used = {}
  local retary = {}
  local div = patall
  for i = 1, n do used[i] = false end
  for i = n, 1, -1 do
    div = math.floor(div / i)
    local v_idx = math.floor(idx / div)
    idx = idx % div
    local tmp_idx = 0
    for j = 1, n do
      if(not used[j]) then
        if(tmp_idx == v_idx) then
          table.insert(retary, j)
          used[j] = true
          break
        else
          tmp_idx = tmp_idx + 1
        end
      end
    end
  end
  return retary
end
local highsc = 0
local mma = math.max
for i = 0, tot - 1 do
  local tbl = getpattern(n, tot, i)
  local sc = 0
  for j = 1, n - 1 do
    for k = j + 1, n do
      if(scores[tbl[j]][tbl[k]] ~= nil) then
        sc = sc + scores[tbl[j]][tbl[k]]
      end
    end
  end
  highsc = mma(highsc, sc)
end
print(highsc)
0