結果

問題 No.699 ペアでチームを作ろう2
ユーザー 👑 obakyanobakyan
提出日時 2019-07-08 23:49:49
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 598 ms / 1,000 ms
コード長 1,125 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 02:08:41
合計ジャッジ時間 5,505 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 31 ms
5,376 KB
testcase_05 AC 99 ms
5,376 KB
testcase_06 AC 110 ms
5,376 KB
testcase_07 AC 444 ms
5,376 KB
testcase_08 AC 543 ms
5,376 KB
testcase_09 AC 598 ms
5,376 KB
testcase_10 AC 547 ms
5,376 KB
testcase_11 AC 549 ms
5,376 KB
testcase_12 AC 552 ms
5,376 KB
testcase_13 AC 541 ms
5,376 KB
testcase_14 AC 545 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

local function getxor(x, y)
  local ret = 0
  local mul = 1
  while(0 < x or 0 < y) do
    if((x % 2) + (y % 2) == 1) then
      ret = ret + mul
    end
    x, y, mul = mfl(x / 2), mfl(y / 2), mul * 2
  end
  return ret
end

local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local n2 = n / 2

local tot = 1
for i = 1, n2 do
  tot = tot * (i * 2 - 1)
end
local box = {}
local maxsum = 0
for i = 0, tot - 1 do
  local sum = 0
  for k = 1, n do box[k] = 0 end
  for j = 1, n2 do
    local pos1 = 0
    for k = 1, n do
      if box[k] == 0 then
        box[k] = j
        pos1 = k
        break
      end
    end
    local div = (n2 + 1 - j) * 2 - 1
    local rel_pos = i % div
    i = mfl(i / div)
    local rel_cnt = 0
    for k = 1, n do
      if box[k] == 0 then
        if rel_cnt == rel_pos then
          box[k] = j
          local pos2 = k
          sum = getxor(sum, a[pos1] + a[pos2])
          break
        else
          rel_cnt = rel_cnt + 1
        end
      end
    end
  end
  -- print(unpack(box))
  maxsum = mma(maxsum, sum)
end
print(maxsum)
0