結果

問題 No.1741 Arrays and XOR Procedure
ユーザー H3PO4H3PO4
提出日時 2021-11-12 22:32:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 81,976 KB
実行使用メモリ 101,476 KB
最終ジャッジ日時 2024-11-25 19:51:41
合計ジャッジ時間 5,109 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
B = map(int, input().split())
MOD = 998244353
MAX = 2 * 10 ** 5 + 10
# https://tjkendev.github.io/procon-library/python/math/factorial.html から拝借しています。
fact = [1] * (MAX + 1)
rfact = [1] * (MAX + 1)
r = 1
for i in range(1, MAX + 1):
    fact[i] = r = r * i % MOD
rfact[MAX] = r = pow(fact[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    rfact[i - 1] = r = r * i % MOD


def comb(n, k, error=0):
    if not 0 <= k <= n:
        return error
    return fact[n] * rfact[k] * rfact[n - k] % MOD


def p2(x):
    res = 0
    while not x % 2:
        x //= 2
        res += 1
    return res


comb2 = [0] * N
for i in range(1, N):
    comb2[i] = comb2[i - 1] + p2(N - i) - p2(i)

cur = 0
ct_odd = 0
ct_even = 0
for b, c in zip(B, comb2):
    if b == -1:
        if c:
            ct_even += 1
        else:
            ct_odd += 1
        continue
    if not c:
        cur ^= b

ans = 0
for x in range(1 - cur, ct_odd + 1, 2):
    ans += comb(ct_odd, x)
    ans %= MOD
ans *= pow(2, ct_even, MOD)
ans %= MOD
print(ans)
0