結果

問題 No.1289 RNG and OR
ユーザー Kiri8128Kiri8128
提出日時 2020-11-14 02:46:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 395 ms / 2,000 ms
コード長 2,114 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 105,068 KB
最終ジャッジ日時 2023-09-30 04:42:53
合計ジャッジ時間 3,962 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,428 KB
testcase_01 AC 77 ms
71,392 KB
testcase_02 AC 72 ms
71,388 KB
testcase_03 AC 73 ms
71,388 KB
testcase_04 AC 76 ms
71,396 KB
testcase_05 AC 74 ms
71,404 KB
testcase_06 AC 73 ms
71,392 KB
testcase_07 AC 74 ms
71,656 KB
testcase_08 AC 73 ms
71,228 KB
testcase_09 AC 76 ms
71,316 KB
testcase_10 AC 79 ms
75,808 KB
testcase_11 AC 78 ms
75,752 KB
testcase_12 AC 81 ms
75,688 KB
testcase_13 AC 92 ms
76,716 KB
testcase_14 AC 94 ms
76,716 KB
testcase_15 AC 96 ms
76,720 KB
testcase_16 AC 106 ms
76,700 KB
testcase_17 AC 126 ms
79,416 KB
testcase_18 AC 163 ms
83,788 KB
testcase_19 AC 239 ms
92,360 KB
testcase_20 AC 395 ms
105,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def or_convolution(A, B):
    n = max(len(A), len(B))
    X = [0] * (1 << (n - 1).bit_length())
    for i, a in enumerate(A):
        for j, b in enumerate(B):
            X[i|j] += a * b
    return X
def and_convolution(A, B):
    n = max(len(A), len(B))
    X = [0] * (1 << (n - 1).bit_length())
    for i, a in enumerate(A):
        for j, b in enumerate(B):
            X[i&j] += a * b
    return X

def zeta_bit(L0): # 下からの累積
    k = (len(L0) - 1).bit_length()
    n = 1 << k
    L = L0[:] + [0] * (n - len(L0))
    for i in range(k):
        for j in range(n):
            if j >> i & 1:
                L[j] += L[j^(1<<i)]
    return L
def mobius_bit(L0): # zeta_bit の逆変換
    k = (len(L0) - 1).bit_length()
    n = 1 << k
    L = L0[:] + [0] * (n - len(L0))
    for i in range(k):
        for j in range(n)[::-1]:
            if j >> i & 1:
                L[j] -= L[j^(1<<i)]
    return L
def zeta_bit_inv(L0): # 上からの累積
    k = (len(L0) - 1).bit_length()
    n = 1 << k
    L = L0[:] + [0] * (n - len(L0))
    for i in range(k):
        for j in range(n)[::-1]:
            if j >> i & 1:
                L[j^(1<<i)] += L[j]
    return L
def mobius_bit_inv(L0): # zeta_bit_inv の逆変換
    k = (len(L0) - 1).bit_length()
    n = 1 << k
    L = L0[:] + [0] * (n - len(L0))
    for i in range(k):
        for j in range(n):
            if j >> i & 1:
                L[j^(1<<i)] -= L[j]
    return L
def popcount_parity(x):
    x ^= x >> 1
    x ^= x >> 2
    x ^= x >> 4
    x ^= x >> 8
    x ^= x >> 16
    return x & 1
def r(a):
    for i in range(1, 10001):
        if i and a * i % P <= 10000:
            return str(a*i%P) + "/" + str(i)
        if i and -a * i % P <= 10000:
            return str(-(-a*i%P)) + "/" + str(i)
    return a
P = 998244353
N = int(input())
A = [int(a) for a in input().split()]
S = sum(A)
iS = pow(S, P - 2, P)
A = [a * iS % P for a in A]
B = zeta_bit(A)
ans = 0
for i, b in enumerate(B[:-1]):
    if popcount_parity(i):
        ans += pow(B[-1] - b, P - 2, P)
    else:
        ans -= pow(B[-1] - b, P - 2, P)
print(ans * (-1) ** N % P)
0