結果

問題 No.130 XOR Minimax
ユーザー 👑 obakyanobakyan
提出日時 2020-04-23 21:31:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 957 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 01:05:36
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 45 ms
6,944 KB
testcase_05 AC 53 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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)
  local mask = 0
  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))
      rec(lb, r, i - 1, score + bls(1, i))
      return
    end
  end
  ret = mmi(ret, score)
end
rec(1, n, 29, 0)
print(ret)
0