結果

問題 No.1741 Arrays and XOR Procedure
ユーザー brthyyjpbrthyyjp
提出日時 2022-01-21 10:24:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 121,420 KB
最終ジャッジ日時 2023-08-16 14:33:32
合計ジャッジ時間 13,731 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
92,148 KB
testcase_01 AC 105 ms
92,500 KB
testcase_02 AC 101 ms
92,132 KB
testcase_03 AC 384 ms
121,420 KB
testcase_04 AC 100 ms
92,280 KB
testcase_05 AC 371 ms
120,964 KB
testcase_06 AC 391 ms
121,296 KB
testcase_07 AC 387 ms
121,176 KB
testcase_08 AC 373 ms
121,012 KB
testcase_09 AC 339 ms
117,568 KB
testcase_10 AC 352 ms
117,884 KB
testcase_11 AC 301 ms
112,020 KB
testcase_12 AC 256 ms
107,536 KB
testcase_13 AC 338 ms
117,484 KB
testcase_14 AC 272 ms
109,656 KB
testcase_15 AC 323 ms
114,580 KB
testcase_16 AC 119 ms
92,956 KB
testcase_17 AC 186 ms
99,876 KB
testcase_18 AC 281 ms
109,620 KB
testcase_19 AC 118 ms
92,920 KB
testcase_20 AC 376 ms
120,972 KB
testcase_21 AC 313 ms
114,476 KB
testcase_22 AC 298 ms
112,020 KB
testcase_23 AC 197 ms
98,856 KB
testcase_24 AC 141 ms
93,188 KB
testcase_25 AC 399 ms
120,668 KB
testcase_26 AC 233 ms
102,528 KB
testcase_27 AC 133 ms
93,072 KB
testcase_28 AC 323 ms
111,808 KB
testcase_29 AC 353 ms
114,536 KB
testcase_30 AC 321 ms
111,772 KB
testcase_31 AC 135 ms
92,784 KB
testcase_32 AC 216 ms
102,392 KB
testcase_33 AC 238 ms
105,596 KB
testcase_34 AC 152 ms
96,312 KB
testcase_35 AC 102 ms
92,564 KB
testcase_36 AC 128 ms
93,236 KB
testcase_37 AC 209 ms
102,360 KB
testcase_38 AC 371 ms
120,832 KB
testcase_39 AC 206 ms
101,120 KB
testcase_40 AC 116 ms
93,160 KB
testcase_41 AC 157 ms
95,772 KB
testcase_42 AC 127 ms
93,120 KB
testcase_43 AC 105 ms
92,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = 10**6
mod = 998244353
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
    fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(range(N)):
    finv[i] = finv[i+1] * (i+1) % mod

def cmb1(n, r, mod):
    if r <0 or r > n:
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod

p = 2
C = [[0]*(p+1) for i in range(p+1)] #C[n][k] > nCk

for i in range(p+1):
    for j in range(i+1):
        if j == 0 or j == i:
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1]+C[i-1][j]

def cmb2(n, k, p):
    ret = 1
    while n > 0:
        ni = n%p
        ki = k%p
        ret *= C[ni][ki]
        ret %= p
        n //= p
        k //= p
    return ret

n = int(input())
B = list(map(int, input().split()))

x = 0
o = 0
e = 0
for i, b in enumerate(B):
    if b != -1:
        if cmb2(n-1, i, 2)%2 == 1:
            x ^= b
    else:
        if cmb2(n-1, i, 2)%2 == 1:
            o += 1
        else:
            e += 1

ans = 0
if x == 0:
    for k in range(o+1):
        if k%2 == 0:
            continue
        ans += cmb1(o, k, mod)*pow(2, e, mod)
        ans %= mod
else:
    for k in range(o+1):
        if k%2 == 1:
            continue
        ans += cmb1(o, k, mod)*pow(2, e, mod)
        ans %= mod
print(ans)
0