結果

問題 No.1876 Xor of Sum
ユーザー 👑 obakyanobakyan
提出日時 2022-03-16 09:34:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,394 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 6,596 KB
最終ジャッジ日時 2023-10-24 14:04:45
合計ジャッジ時間 38,858 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 376 ms
4,348 KB
testcase_04 AC 1,074 ms
4,532 KB
testcase_05 AC 20 ms
4,348 KB
testcase_06 TLE -
testcase_07 AC 27 ms
4,348 KB
testcase_08 AC 22 ms
4,348 KB
testcase_09 AC 953 ms
4,532 KB
testcase_10 AC 267 ms
4,348 KB
testcase_11 AC 1,571 ms
4,532 KB
testcase_12 AC 356 ms
4,348 KB
testcase_13 AC 816 ms
4,532 KB
testcase_14 AC 576 ms
4,532 KB
testcase_15 AC 720 ms
4,532 KB
testcase_16 AC 15 ms
4,348 KB
testcase_17 AC 1,727 ms
4,532 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

-- True-False DP (bitset)
local mfl, mce = math.floor, math.ceil
local bls, brs = bit.lshift, bit.rshift
local bor, band = bit.bor, bit.band
local bxor = bit.bxor
local TFDP = {}

TFDP.initialize = function(self, lim)
  self.lim = lim
  self.sz = 30
  self.way = true
  self.bcnt = mce((lim + 1) / self.sz)
  self.b1, self.b2 = {1}, {}
  for i = 2, self.bcnt do
    self.b1[i] = 0
  end
  self.curmax = 0
end

TFDP.add = function(self, v)
  local src = self.way and self.b1 or self.b2
  local dst = self.way and self.b2 or self.b1
  self.way = not self.way
  local bcnt = self.bcnt
  for i = 1, bcnt do
    dst[i] = src[i]
  end
  local sz = self.sz
  local jump, rem = mfl(v / sz), v % sz
  for i = 1, bcnt - jump do
    local v1 = src[i] % bls(1, sz - rem)
    dst[i + jump] = bxor(dst[i + jump], v1 * bls(1, rem))
  end
  for i = 1, bcnt - jump - 1 do
    local v2 = brs(src[i], sz - rem)
    dst[i + jump + 1] = bxor(dst[i + jump + 1], v2)
  end
end

TFDP.query = function(self, x)
  local group = mfl(x / self.sz) + 1
  local idx = x - (group - 1) * self.sz
  local tbl = self.way and self.b1 or self.b2
  return band(tbl[group], bls(1, idx)) ~= 0
end

local tf = TFDP
local n = io.read("*n")
local lim = n * 2000
tf:initialize(lim)
for i = 1, n do
  local a = io.read("*n")
  tf:add(a)
end
local ret = 0
for i = 1, lim do
  if tf:query(i) then
    ret = bxor(ret, i)
  end
end
print(ret)
0