結果

問題 No.1763 Many Balls
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-11-09 16:32:10
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,024 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 250,740 KB
最終ジャッジ日時 2024-04-20 09:55:06
合計ジャッジ時間 96,544 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
53,888 KB
testcase_01 AC 42 ms
53,888 KB
testcase_02 AC 194 ms
77,732 KB
testcase_03 AC 41 ms
53,888 KB
testcase_04 AC 43 ms
53,760 KB
testcase_05 AC 41 ms
53,888 KB
testcase_06 AC 4,133 ms
178,336 KB
testcase_07 AC 7,590 ms
234,556 KB
testcase_08 AC 1,177 ms
101,460 KB
testcase_09 AC 6,978 ms
226,692 KB
testcase_10 AC 8,410 ms
250,740 KB
testcase_11 AC 497 ms
86,776 KB
testcase_12 AC 1,243 ms
103,796 KB
testcase_13 AC 3,106 ms
142,772 KB
testcase_14 AC 989 ms
98,460 KB
testcase_15 AC 1,539 ms
112,156 KB
testcase_16 AC 2,085 ms
126,240 KB
testcase_17 AC 4,077 ms
166,456 KB
testcase_18 AC 4,103 ms
175,552 KB
testcase_19 AC 2,024 ms
125,784 KB
testcase_20 AC 8,177 ms
248,072 KB
testcase_21 AC 8,074 ms
248,388 KB
testcase_22 AC 2,000 ms
124,424 KB
testcase_23 AC 8,318 ms
249,964 KB
testcase_24 AC 8,363 ms
249,288 KB
testcase_25 AC 8,184 ms
250,324 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

class FFT():
    def primitive_root_constexpr(self,m):
        if m==2:return 1
        if m==167772161:return 3
        if m==469762049:return 3
        if m==754974721:return 11
        if m==998244353:return 3
        divs=[0]*20
        divs[0]=2
        cnt=1
        x=(m-1)//2
        while(x%2==0):x//=2
        i=3
        while(i*i<=x):
            if (x%i==0):
                divs[cnt]=i
                cnt+=1
                while(x%i==0):
                    x//=i
            i+=2
        if x>1:
            divs[cnt]=x
            cnt+=1
        g=2
        while(1):
            ok=True
            for i in range(cnt):
                if pow(g,(m-1)//divs[i],m)==1:
                    ok=False
                    break
            if ok:
                return g
            g+=1
    def bsf(self,x):
        res=0
        while(x%2==0):
            res+=1
            x//=2
        return res
    butterfly_first=True
    butterfly_inv_first=True
    sum_e=[0]*30
    sum_ie=[0]*30
    def __init__(self,MOD):
        self.mod=MOD
        self.g=self.primitive_root_constexpr(self.mod)
    def butterfly(self,a):
        n=len(a)
        h=(n-1).bit_length()
        if self.butterfly_first:
            self.butterfly_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_e[i]=((es[i]*now)%self.mod)
                now*=ies[i]
                now%=self.mod
        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()
        if self.butterfly_inv_first:
            self.butterfly_inv_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_ie[i]=((ies[i]*now)%self.mod)
                now*=es[i]
                now%=self.mod
        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]

def inv_gcd(a,b):
    a=a%b
    if a==0:
        return (b,0)
    s=b;t=a
    m0=0;m1=1
    while(t):
        u=s//t
        s-=t*u
        m0-=m1*u
        s,t=t,s
        m0,m1=m1,m0
    if m0<0:
        m0+=b//s
    return (s,m0)
def crt(r,m):
    assert len(r)==len(m)
    n=len(r)
    r0=0;m0=1
    for i in range(n):
        assert 1<=m[i]
        r1=r[i]%m[i]
        m1=m[i]
        if m0<m1:
            r0,r1=r1,r0
            m0,m1=m1,m0
        if (m0%m1==0):
            if (r0%m1!=r1):
                return (0,0)
            continue
        g,im=inv_gcd(m0,m1)
        u1=m1//g
        if ((r1-r0)%g):
            return (0,0)
        x=(r1-r0)//g % u1*im%u1
        r0+=x*m0
        m0*=u1
        if r0<0:
            r0+=m0
    return (r0,m0)
def modpow(a,b,m):
  res=1
  while b:
    if b%2:
      res*=a
      res%=m
    a*=a
    a%=m
    b//=2
  return res
def convolution_mod(a,b):
    mod=90001
    n=len(a)
    m=len(b)
    for i in range(n):a[i]%=mod
    for i in range(m):b[i]%=mod
    mod1=167772161
    mod2=469762049
    ntt1=FFT(mod1)
    ntt2=FFT(mod2)
    x=ntt1.convolution(a,b)
    y=ntt2.convolution(a,b)
    ret=[0 for i in range(n)]
    for i in range(n):
        tmp=crt((x[i],y[i]),(mod1,mod2))
        ret[i]=tmp[0]%mod
    return ret
n,m=map(int,input().split())
n%=90000
if n==0:
    n=90000;
dp=[0 for i in range(n+1)]
dp[0]=1
f=[0 for i in range(n+1)]
f[0]=1
for i in range(1,n+1):
  f[i]=f[i-1]*modpow(i,89999,90001)
  f[i]%=90001
for i in range(m):
  dp2=[0 for i in range(n+1)]
  k,*a=map(int,input().split())
  for j in range(k):
    for x in range(0,n+1,a[j]):
      dp2[x]=f[x]
  dp=convolution_mod(dp,dp2)
dp=convolution_mod(dp,f)
for i in range(1,n+1):
  dp[n]*=i
  dp[n]%=90001
print(dp[n])
0