結果

問題 No.1189 Sum is XOR
ユーザー 👑 obakyanobakyan
提出日時 2021-05-27 23:05:29
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 09:27:37
合計ジャッジ時間 2,176 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
5,248 KB
testcase_01 AC 50 ms
5,376 KB
testcase_02 AC 47 ms
5,376 KB
testcase_03 AC 19 ms
5,376 KB
testcase_04 AC 17 ms
5,376 KB
testcase_05 AC 28 ms
5,376 KB
testcase_06 AC 38 ms
5,376 KB
testcase_07 AC 21 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 8 ms
5,376 KB
testcase_11 AC 21 ms
5,376 KB
testcase_12 AC 44 ms
5,376 KB
testcase_13 AC 51 ms
5,376 KB
testcase_14 AC 40 ms
5,376 KB
testcase_15 AC 30 ms
5,376 KB
testcase_16 AC 32 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 23 ms
5,376 KB
testcase_19 AC 45 ms
5,376 KB
testcase_20 AC 52 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local bor = bit.bor
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 function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local function modinv(src)
  return modpow(src, mod - 2)
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 alltask = {{}}
for i = 1, 1023 do
  alltask[1][i] = 0
end
for i = 1, n do
  alltask[1][a[i]] = alltask[1][a[i]] + 1
end
local at1 = alltask[1]
for ik = 2, k do
  alltask[ik] = {}
  local atp = alltask[ik - 1]
  local atk = alltask[ik]
  for i = 1, 1023 do atk[i] = 0 end
  for i = 1, 1023 do
    for j = 1, 1023 do
      if i + j == bor(i, j) then
        local dst = i + j
        atk[dst] = badd(atk[dst], bmul(at1[i], atp[j]))
      end
    end
  end
  local inv = modinv(ik)
  for i = 1, 1023 do atk[i] = bmul(atk[i], inv) end
end
local ret = 0
for i = 1, 1023 do
  ret = badd(ret, alltask[k][i])
end
print(ret)
0