結果

問題 No.1856 Mex Sum 2
ユーザー googol_S0googol_S0
提出日時 2022-09-26 05:09:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 92 ms / 3,000 ms
コード長 4,763 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 83,440 KB
最終ジャッジ日時 2023-08-24 02:42:41
合計ジャッジ時間 10,117 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
82,992 KB
testcase_01 AC 89 ms
82,864 KB
testcase_02 AC 88 ms
83,056 KB
testcase_03 AC 84 ms
83,000 KB
testcase_04 AC 85 ms
82,944 KB
testcase_05 AC 83 ms
82,792 KB
testcase_06 AC 83 ms
82,920 KB
testcase_07 AC 85 ms
83,008 KB
testcase_08 AC 85 ms
82,920 KB
testcase_09 AC 84 ms
82,996 KB
testcase_10 AC 84 ms
82,812 KB
testcase_11 AC 84 ms
82,916 KB
testcase_12 AC 84 ms
83,020 KB
testcase_13 AC 85 ms
82,932 KB
testcase_14 AC 86 ms
82,932 KB
testcase_15 AC 83 ms
82,848 KB
testcase_16 AC 83 ms
82,812 KB
testcase_17 AC 91 ms
82,932 KB
testcase_18 AC 82 ms
83,028 KB
testcase_19 AC 84 ms
83,168 KB
testcase_20 AC 84 ms
83,008 KB
testcase_21 AC 84 ms
83,020 KB
testcase_22 AC 84 ms
82,920 KB
testcase_23 AC 84 ms
82,852 KB
testcase_24 AC 92 ms
83,168 KB
testcase_25 AC 84 ms
82,904 KB
testcase_26 AC 85 ms
82,972 KB
testcase_27 AC 84 ms
83,164 KB
testcase_28 AC 83 ms
82,900 KB
testcase_29 AC 86 ms
83,116 KB
testcase_30 AC 85 ms
82,944 KB
testcase_31 AC 85 ms
82,928 KB
testcase_32 AC 85 ms
82,932 KB
testcase_33 AC 85 ms
82,948 KB
testcase_34 AC 84 ms
82,888 KB
testcase_35 AC 84 ms
83,108 KB
testcase_36 AC 85 ms
83,048 KB
testcase_37 AC 84 ms
82,816 KB
testcase_38 AC 83 ms
82,980 KB
testcase_39 AC 88 ms
83,020 KB
testcase_40 AC 84 ms
82,904 KB
testcase_41 AC 84 ms
82,792 KB
testcase_42 AC 89 ms
83,224 KB
testcase_43 AC 88 ms
83,144 KB
testcase_44 AC 90 ms
83,108 KB
testcase_45 AC 89 ms
83,252 KB
testcase_46 AC 89 ms
83,440 KB
testcase_47 AC 90 ms
83,120 KB
testcase_48 AC 89 ms
82,944 KB
testcase_49 AC 88 ms
83,300 KB
testcase_50 AC 89 ms
83,220 KB
testcase_51 AC 87 ms
82,948 KB
testcase_52 AC 89 ms
83,296 KB
testcase_53 AC 89 ms
83,356 KB
testcase_54 AC 88 ms
83,156 KB
testcase_55 AC 89 ms
83,284 KB
testcase_56 AC 89 ms
83,272 KB
testcase_57 AC 89 ms
83,320 KB
testcase_58 AC 88 ms
83,308 KB
testcase_59 AC 91 ms
83,148 KB
testcase_60 AC 89 ms
83,152 KB
testcase_61 AC 90 ms
83,324 KB
testcase_62 AC 91 ms
83,148 KB
testcase_63 AC 89 ms
83,316 KB
testcase_64 AC 91 ms
83,272 KB
testcase_65 AC 89 ms
83,276 KB
testcase_66 AC 89 ms
83,236 KB
権限があれば一括ダウンロードができます

ソースコード

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
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]

N,M=map(int,input().split())
M+=1
ANS=0
for k in range(min(N,M)+1):
  ANS=(ANS+pow(2*M-k,N,mod)*(cmb(min(N,M)+1,k+1)-max(0,1-k))*(1-2*(k&1)))%mod
print(ANS)
0