結果

問題 No.2062 Sum of Subset mod 999630629
ユーザー googol_S0googol_S0
提出日時 2022-08-26 22:24:57
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,581 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,396 KB
実行使用メモリ 297,288 KB
最終ジャッジ日時 2024-04-22 02:23:25
合計ジャッジ時間 10,200 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
69,104 KB
testcase_01 AC 58 ms
68,276 KB
testcase_02 AC 62 ms
68,052 KB
testcase_03 AC 59 ms
67,592 KB
testcase_04 AC 59 ms
68,800 KB
testcase_05 AC 59 ms
67,612 KB
testcase_06 AC 57 ms
67,688 KB
testcase_07 AC 59 ms
68,116 KB
testcase_08 AC 78 ms
91,152 KB
testcase_09 AC 74 ms
84,816 KB
testcase_10 AC 72 ms
84,296 KB
testcase_11 AC 90 ms
95,904 KB
testcase_12 AC 90 ms
93,876 KB
testcase_13 AC 84 ms
91,032 KB
testcase_14 AC 90 ms
95,436 KB
testcase_15 AC 83 ms
91,352 KB
testcase_16 AC 92 ms
95,116 KB
testcase_17 AC 90 ms
94,500 KB
testcase_18 AC 83 ms
92,624 KB
testcase_19 AC 83 ms
90,760 KB
testcase_20 AC 89 ms
94,108 KB
testcase_21 AC 83 ms
92,144 KB
testcase_22 AC 86 ms
92,972 KB
testcase_23 AC 77 ms
87,636 KB
testcase_24 AC 75 ms
87,404 KB
testcase_25 AC 102 ms
97,316 KB
testcase_26 AC 116 ms
97,196 KB
testcase_27 AC 109 ms
97,240 KB
testcase_28 AC 110 ms
96,932 KB
testcase_29 AC 100 ms
97,528 KB
testcase_30 AC 206 ms
141,744 KB
testcase_31 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
#ごめん

def cmb(n,r):
  if r<0 or r>n:
    return 0
  return ((g1[n]*g2[r]%mod)*g2[n-r])%mod

N=300000
g1=[1]*(N+3)
for i in range(2,N+3):
  g1[i]=g1[i-1]*i%mod
g2=[0]*len(g1)
g2[-1]=pow(g1[-1],mod-2,mod)
for i in range(N+1,-1,-1):
  g2[i]=g2[i+1]*(i+1)%mod
inv=[0]*(N+3)
for i in range(1,N+3):
  inv[i]=g2[i]*g1[i-1]%mod


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,b=list(a),list(b)
        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]

C=[0]*10000
for i in range(N):
  C[10000-A[i]]+=1
X=dict()
X[0]=1
def f(x,y):
  kx=list(x.keys())
  ky=list(y.keys())
  z=dict()
  for i in range(len(kx)):
    for j in range(len(ky)):
      p,q=kx[i],ky[j]
      r=p+q
      if r>K:
        continue
      z[r]=(z.get(r,0)+x[p]*y[q])%mod
  return z

K=S-MOD
for i in range(10000):
  if C[i]==0:
    continue
  v=dict()
  for j in range(C[i],-1,-1):
    p=(10000-i)*(C[i]-j)
    if p>K:
      break
    v[p]=(v.get(p,0)+cmb(C[i],j))%mod
  X=f(X,v)
print((pow(2,N-1,mod)*S-sum(X.values())*(MOD-mod))%mod)
0