結果

問題 No.1189 Sum is XOR
ユーザー 👑 obakyanobakyan
提出日時 2021-05-27 22:39:20
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 2,366 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 08:55:04
合計ジャッジ時間 2,352 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 22 ms
5,376 KB
testcase_04 AC 19 ms
5,376 KB
testcase_05 AC 31 ms
5,376 KB
testcase_06 AC 44 ms
5,376 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 10 ms
5,376 KB
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 AC 7 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local bxor = bit.bxor
local mod = 998244353
local mfl = math.floor
local function bmul(x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % mod
end
local function badd(x, y)
  return (x + y) % mod
end

local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
if 10 < k then print(0) os.exit() end

local tot = bls(1, 10)
local alltask = {}
local stagetask = {}
for i = 1, 10 do
  stagetask[i] = {}
end
for i = 1, tot - 1 do
  alltask[i] = {}
  for j = 1, k do
    alltask[i][j] = 0
  end
end
for i = 1, tot - 1 do
  local ti = i
  local cnt = 0
  for j = 1, 10 do
    if ti % 2 == 1 then
      cnt = cnt + 1
    end
    ti = brs(ti, 1)
  end
  table.insert(stagetask[cnt], i)
end

for i = 1, n do
  alltask[a[i]][1] = alltask[a[i]][1] + 1
end

local function grayCode(x)
  return bxor(x, brs(x, 1))
end

local g_dst = 0
local g_box = {}
local g_src = 0
local function add_func(idx)
  g_src = g_src + bls(1, g_box[idx] - 1)
end
local function rm_func(idx)
  g_src = g_src - bls(1, g_box[idx] - 1)
end
local function work_func()
  if g_src * 2 < g_dst then
    local lim = mmi(k, #g_box)
    local at1 = alltask[g_src]
    local at2 = alltask[g_dst - g_src]
    local atd = alltask[g_dst]
    for i = 2, lim do
      local v = 0
      for j = 1, i - 1 do
        v = badd(v, bmul(at1[j], at2[i - j]))
      end
      atd[i] = badd(atd[i], v)
    end
  end
end

local bpos = {}
for i = 1, 10 do
  bpos[bls(1, i - 1)] = i
end

local function grayWalk(size)
  local prv = 0
  local total = bls(1, size) - 1
  -- work_func()
  for i = 1, total do
    local v = grayCode(i)
    if prv < v then
      prv, v = v, v - prv
      add_func(bpos[v])
    else
      prv, v = v, prv - v
      rm_func(bpos[v])
    end
    work_func()
  end
end

for stage = 2, 10 do
  local stlen = #stagetask[stage]
  for i_stagetask = 1, stlen do
    local tmp = stagetask[stage][i_stagetask]
    g_dst = tmp
    g_src = 0
    local c = 0
    for j = 1, 10 do
      if tmp % 2 == 1 then
        c = c + 1
        g_box[c] = j
      end
      tmp = brs(tmp, 1)
    end
    grayWalk(stage)
  end
end

local ret = 0
for i = 1, 1023 do
  ret = badd(ret, alltask[i][k])
end
print(ret)
0