結果

問題 No.1289 RNG and OR
ユーザー 已经死了
提出日時 2025-09-16 15:33:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 1,682 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 82,652 KB
実行使用メモリ 132,640 KB
最終ジャッジ日時 2025-09-16 15:33:31
合計ジャッジ時間 6,284 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import os,sys,random,threading
from random import randint,choice,shuffle
from copy import deepcopy
from io import BytesIO,IOBase
from types import GeneratorType
from functools import lru_cache,reduce
from bisect import bisect_left,bisect_right
from collections import Counter,defaultdict,deque
from itertools import accumulate,combinations,permutations
from heapq import  heapify,heappop,heappush
from typing import Generic,Iterable,Iterator,TypeVar,Union,List
from math import sqrt
from decimal import Decimal,getcontext
from sys import stdin, stdout, setrecursionlimit
input = lambda: sys.stdin.readline().rstrip("\r\n")
MI = lambda :map(int,input().split())
li = lambda :list(MI())
ii = lambda :int(input())
mod = 10**9+7
inf = 1<<64


mod=998244353
def popcnt(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

def inv(x):
    return pow(x,mod-2,mod)

n=ii()
f=li()
tot=sum(f)
it=inv(tot)
for i in range(n):
    for s in range(1<<n):
        if s>>i&1==1:
            f[s]+=f[s^(1<<i)]
            f[s]%=mod
t=(1<<n)-1
for i in range(1<<n):
    f[i]=f[i]*it%mod

c=[0]*(1<<n)
for s in range(1,1<<n):
    if popcnt(s)%2:
        c[s]=inv(1-f[t^s])
    else:
        c[s]=-inv(1-f[t^s])

for i in range(n):
    for s in range(1<<n):
        if s>>i&1:
            c[s]+=c[s^(1<<i)]
            c[s]%=mod

print(c[t^0])


0