結果

問題 No.1741 Arrays and XOR Procedure
ユーザー 👑 obakyanobakyan
提出日時 2022-01-16 23:31:50
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,208 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 18:51:39
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 42 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 40 ms
5,376 KB
testcase_06 AC 43 ms
5,376 KB
testcase_07 AC 44 ms
5,376 KB
testcase_08 AC 34 ms
5,376 KB
testcase_09 AC 36 ms
5,376 KB
testcase_10 AC 38 ms
5,376 KB
testcase_11 AC 30 ms
5,376 KB
testcase_12 AC 23 ms
5,376 KB
testcase_13 AC 37 ms
5,376 KB
testcase_14 AC 25 ms
5,376 KB
testcase_15 AC 33 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 13 ms
5,376 KB
testcase_18 AC 27 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 40 ms
5,376 KB
testcase_21 AC 32 ms
5,376 KB
testcase_22 AC 30 ms
5,376 KB
testcase_23 AC 12 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 44 ms
5,376 KB
testcase_26 AC 20 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 35 ms
5,376 KB
testcase_29 AC 37 ms
5,376 KB
testcase_30 AC 32 ms
5,376 KB
testcase_31 AC 5 ms
5,376 KB
testcase_32 AC 20 ms
5,376 KB
testcase_33 AC 22 ms
5,376 KB
testcase_34 AC 10 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 18 ms
5,376 KB
testcase_38 AC 43 ms
5,376 KB
testcase_39 AC 15 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 10 ms
5,376 KB
testcase_42 AC 4 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mod = 998244353
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 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 n = io.read("*n")
local b = {}
for i = 1, n do
  b[i] = io.read("*n")
end
local c2 = 0
local bias, change = 0, 0
if b[1] == 1 then
  bias = 1
elseif b[1] == -1 then
  change = change + 1
end
local ret = 1
n = n - 1
for i = 1, n do
  local mul = n + 1 - i
  local div = i
  while mul % 2 == 0 do
    c2 = c2 + 1
    mul = mfl(mul / 2)
  end
  while div % 2 == 0 do
    c2 = c2 - 1
    div = mfl(div / 2)
  end
  if 0 == c2 then
    -- print("!", i)
    if b[i + 1] == 1 then
      bias = 1 - bias
    elseif b[i + 1] == -1 then
      change = change + 1
    end
  else
    if b[i + 1] == -1 then
      ret = (ret + ret) % mod
    end
  end
end
if change == 0 then
  print(bias * ret)
else
  print(bmul(ret, modpow(2, change - 1)))
end
0