結果

問題 No.130 XOR Minimax
ユーザー 👑 obakyanobakyan
提出日時 2020-04-23 21:36:22
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 87 ms / 5,000 ms
コード長 973 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 5,156 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-10 00:28:17
合計ジャッジ時間 2,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 53 ms
4,348 KB
testcase_05 AC 61 ms
4,352 KB
testcase_06 AC 60 ms
4,352 KB
testcase_07 AC 87 ms
4,352 KB
testcase_08 AC 79 ms
4,352 KB
testcase_09 AC 13 ms
4,352 KB
testcase_10 AC 24 ms
4,348 KB
testcase_11 AC 71 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 63 ms
4,348 KB
testcase_14 AC 86 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 59 ms
4,348 KB
testcase_17 AC 61 ms
4,348 KB
testcase_18 AC 67 ms
4,348 KB
testcase_19 AC 79 ms
4,352 KB
testcase_20 AC 39 ms
4,352 KB
testcase_21 AC 84 ms
4,352 KB
testcase_22 AC 19 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local bls, brs = bit.lshift, bit.rshift
local mfl = math.floor
local mmi, mma = math.min, math.max
local function comp(a, b)
  return a < b
end

local function lower_bound(ary, min, max, x)
  if not comp(ary[min], x) then return min end
  if comp(ary[max], x) then return max + 1 end
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
table.sort(a)
local ret = 1000000007
local function rec(l, r, stage, score, mask)
  for i = stage, 0, -1 do
    local lb = lower_bound(a, l, r, mask + bls(1, i))
    if lb <= l then
      mask = mask + bls(1, i)
    elseif r < lb then
    else
      rec(l, lb - 1, i - 1, score + bls(1, i), mask)
      rec(lb, r, i - 1, score + bls(1, i), mask + bls(1, i))
      return
    end
  end
  ret = mmi(ret, score)
end
rec(1, n, 29, 0, 0)
print(ret)
0