結果

問題 No.1289 RNG and OR
ユーザー ayaoniayaoni
提出日時 2020-11-14 07:36:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 409 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 113,940 KB
最終ジャッジ日時 2023-09-30 04:45:42
合計ジャッジ時間 3,826 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,504 KB
testcase_01 AC 76 ms
71,520 KB
testcase_02 AC 77 ms
71,556 KB
testcase_03 AC 79 ms
71,456 KB
testcase_04 AC 77 ms
71,132 KB
testcase_05 AC 77 ms
71,344 KB
testcase_06 AC 76 ms
71,548 KB
testcase_07 AC 76 ms
71,476 KB
testcase_08 AC 76 ms
71,292 KB
testcase_09 AC 75 ms
71,340 KB
testcase_10 AC 84 ms
76,236 KB
testcase_11 AC 83 ms
76,140 KB
testcase_12 AC 86 ms
76,120 KB
testcase_13 AC 100 ms
76,768 KB
testcase_14 AC 99 ms
76,700 KB
testcase_15 AC 101 ms
76,932 KB
testcase_16 AC 111 ms
77,176 KB
testcase_17 AC 130 ms
79,668 KB
testcase_18 AC 174 ms
85,456 KB
testcase_19 AC 248 ms
97,076 KB
testcase_20 AC 409 ms
113,940 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 = A
for i in range(1,N+1):
    for j in range(1<<N):
        if (1<<(i-1))&j:
            dp[j] += dp[j&~(1<<(i-1))]

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

print(ans)
0