結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー googol_S0googol_S0
提出日時 2022-08-26 21:37:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 3,026 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 123,052 KB
最終ジャッジ日時 2024-04-21 23:36:31
合計ジャッジ時間 16,172 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,608 KB
testcase_01 AC 39 ms
52,480 KB
testcase_02 AC 40 ms
52,608 KB
testcase_03 AC 40 ms
52,608 KB
testcase_04 AC 40 ms
52,480 KB
testcase_05 AC 40 ms
52,480 KB
testcase_06 AC 40 ms
52,736 KB
testcase_07 AC 40 ms
52,608 KB
testcase_08 AC 68 ms
78,848 KB
testcase_09 AC 61 ms
74,880 KB
testcase_10 AC 56 ms
73,344 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 60 ms
77,672 KB
testcase_24 AC 59 ms
77,056 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 WA -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
mod=998244353
MOD=999630629
S=sum(A)
if S<MOD:
  print(pow(2,N-1,mod)*S%mod)
  exit()

class FPS:
    sum_e=(911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601, 842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497)
    sum_ie=(86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543, 109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951)
    mod=998244353
    g=3
    def butterfly(self,a):
        n=len(a)
        h=(n-1).bit_length()
        for ph in range(1,h+1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            now=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]*now
                    r%=self.mod
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=l-r
                    a[i+offset+p]%=self.mod
                now*=self.sum_e[(~s & -~s).bit_length()-1]
                now%=self.mod
    def butterfly_inv(self,a):
        n=len(a)
        h=(n-1).bit_length()
        for ph in range(h,0,-1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            inow=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=(l-r)*inow
                    a[i+offset+p]%=self.mod
                inow*=self.sum_ie[(~s & -~s).bit_length()-1]
                inow%=self.mod
    def convolution(self,a,b):
        n=len(a);m=len(b)
        if not(a) or not(b):
            return []
        if min(n,m)<=40:
            if n<m:
                n,m=m,n
                a,b=b,a
            res=[0]*(n+m-1)
            for i in range(n):
                for j in range(m):
                    res[i+j]+=a[i]*b[j]
                    res[i+j]%=self.mod
            return res
        z=1<<((n+m-2).bit_length())
        a=a+[0]*(z-n)
        b=b+[0]*(z-m)
        self.butterfly(a)
        self.butterfly(b)
        c=[0]*z
        for i in range(z):
            c[i]=(a[i]*b[i])%self.mod
        self.butterfly_inv(c)
        iz=pow(z,self.mod-2,self.mod)
        for i in range(n+m-1):
            c[i]=(c[i]*iz)%self.mod
        return c[:n+m-1]

from heapq import *
Q=[]
for i in range(N):
  A[i]=10000-A[i]
  v=[0]*(A[i]+1)
  v[0]=1
  v[A[i]]=1
  Q.append((A[i],tuple(v)))
heapify(Q)
while len(Q)>1:
  p=heappop(Q)
  q=heappop(Q)
  heappush(Q,(p[0]+q[0],tuple(FPS().convolution(p[1],q[1]))))
p=heappop(Q)[1]
ANS=pow(2,N-1,mod)*S%mod
for i in range(min(S-MOD+1,len(p))):
  ANS=(ANS-(MOD-mod)*p[i])%mod
print(ANS)
0