結果

問題 No.1279 Array Battle
ユーザー 👑 obakyanobakyan
提出日時 2020-11-15 20:36:26
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 527 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 07:06:25
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 47 ms
4,380 KB
testcase_14 AC 45 ms
4,376 KB
testcase_15 AC 521 ms
4,376 KB
testcase_16 AC 524 ms
4,376 KB
testcase_17 AC 526 ms
4,376 KB
testcase_18 AC 527 ms
4,380 KB
testcase_19 AC 517 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local mfl = math.floor

local function get_ary_from_idx(idx, n)
  idx = idx - 1
  local box = {}
  for i = 1, n do box[i] = true end
  local rettbl = {}
  for i = n, 1, -1 do
    local pos = idx % i + 1
    idx = mfl(idx / i)
    local cnt = 0
    for j = 1, n do
      if box[j] then
        cnt = cnt + 1
        if cnt == pos then
          box[j] = false
          table.insert(rettbl, j)
          break
        end
      end
    end
  end
  return rettbl
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 retval, retcnt = -1, 0
local allpat = 1
for i = 1, n do
  allpat = allpat * i
end
for i = 1, allpat do
  local z = get_ary_from_idx(i, n)
  local v = 0
  for j = 1, n do
    v = v + mma(0, a[z[j]] - b[j])
  end
  if retval < v then
    retval, retcnt = v, 1
  elseif retval == v then
    retcnt = retcnt + 1
  end
end
print(retcnt)
0