結果

問題 No.1753 Don't cheat.
ユーザー nok0nok0
提出日時 2021-06-20 00:28:12
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,042 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 87,776 KB
最終ジャッジ日時 2023-08-30 06:19:31
合計ジャッジ時間 8,847 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353


def fwht(a) -> None:
    n = len(a)
    i = 1
    while i < n:
        for j in range(n):
            if (j & i) == 0:
                x, y = a[j], a[j | i]
                a[j] = (x + y) % MOD
                a[j | i] = (x - y) % MOD
        i *= 2


def ifwht(a) -> None:
    inv_2 = pow(2, MOD - 2, MOD)
    n = len(a)
    i = 1
    while i < n:
        for j in range(n):
            if (j & i) == 0:
                x, y = a[j], a[j | i]
                a[j] = (x + y) * inv_2 % MOD
                a[j | i] = (x - y) * inv_2 % MOD
        i *= 2


sz = 1 << 11
n = int(input())
a = list(map(int, input().split()))
while len(a) < sz:
    a.append(0)
s = sum(a)
sinv = pow(s, MOD - 2, MOD)
f = [0 for i in range(sz)]
f[0] = 1
for i in range(1, sz):
    f[i] = -a[i] * sinv % MOD
res = 0
for x in range(1, sz):
    g = f.copy()
    g[x] = 0
    fwht(g)
    for i in range(len(g)):
        g[i] = pow(g[i], MOD - 2, MOD)
    ifwht(g)
    res += g[x]
    res %= MOD
res *= a[0]
res %= MOD
res *= sinv
res %= MOD
print(res)
0