結果

問題 No.1289 RNG and OR
ユーザー ayaoniayaoni
提出日時 2020-11-14 07:31:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 600 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 139,120 KB
最終ジャッジ日時 2023-09-30 04:45:25
合計ジャッジ時間 4,108 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,152 KB
testcase_01 AC 77 ms
71,684 KB
testcase_02 AC 78 ms
71,632 KB
testcase_03 AC 80 ms
71,424 KB
testcase_04 AC 77 ms
71,492 KB
testcase_05 AC 78 ms
71,352 KB
testcase_06 AC 77 ms
71,588 KB
testcase_07 AC 79 ms
71,360 KB
testcase_08 AC 78 ms
71,668 KB
testcase_09 AC 78 ms
71,644 KB
testcase_10 AC 83 ms
76,316 KB
testcase_11 AC 85 ms
76,600 KB
testcase_12 AC 89 ms
76,400 KB
testcase_13 AC 98 ms
76,948 KB
testcase_14 AC 99 ms
77,048 KB
testcase_15 AC 107 ms
77,184 KB
testcase_16 AC 124 ms
81,448 KB
testcase_17 AC 157 ms
87,312 KB
testcase_18 AC 200 ms
92,464 KB
testcase_19 AC 335 ms
103,680 KB
testcase_20 AC 600 ms
139,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))


def popcount(n):
    c = (n & 0x5555555555555555) + ((n >> 1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c >> 2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c >> 4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c >> 8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c >> 16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c >> 32) & 0x00000000ffffffff)
    return c


N = I()
A = LI()
s = sum(A)
mod = 998244353

dp = [[0]*(N+1) for _ in range(1<<N)]
for i in range(1<<N):
    for j in range(N+1):
        if j == 0:
            dp[i][j] = A[i]
            continue
        dp[i][j] += dp[i][j-1]
        if i&(1<<(j-1)):
            dp[i][j] += dp[i&~(1<<(j-1))][j-1]

ans = 0
for i in range(1,1<<N):
    x = popcount(i)
    y = ((1<<N)-1)^i
    a = s*pow(s-dp[y][-1],mod-2,mod)
    if x % 2:
        ans += a
    else:
        ans -= a
    ans %= mod

print(ans)
0