結果

問題 No.1241 Eternal Tours
ユーザー vwxyzvwxyz
提出日時 2023-11-18 18:47:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 5,878 bytes
コンパイル時間 1,040 ms
コンパイル使用メモリ 13,440 KB
実行使用メモリ 108,288 KB
最終ジャッジ日時 2024-09-26 05:53:37
合計ジャッジ時間 9,061 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
11,520 KB
testcase_01 AC 34 ms
11,264 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def Extended_Euclid(n,m):
    stack=[]
    while m:
        stack.append((n,m))
        n,m=m,n%m
    if n>=0:
        x,y=1,0
    else:
        x,y=-1,0
    for i in range(len(stack)-1,-1,-1):
        n,m=stack[i]
        x,y=y,x-(n//m)*y
    return x,y

class MOD:
    def __init__(self,p,e=None):
        self.p=p
        self.e=e
        if self.e==None:
            self.mod=self.p
        else:
            self.mod=self.p**self.e

    def Pow(self,a,n):
        a%=self.mod
        if n>=0:
            return pow(a,n,self.mod)
        else:
            #assert math.gcd(a,self.mod)==1
            x=Extended_Euclid(a,self.mod)[0]
            return pow(x,-n,self.mod)

    def Build_Fact(self,N):
        assert N>=0
        self.factorial=[1]
        if self.e==None:
            for i in range(1,N+1):
                self.factorial.append(self.factorial[-1]*i%self.mod)
        else:
            self.cnt=[0]*(N+1)
            for i in range(1,N+1):
                self.cnt[i]=self.cnt[i-1]
                ii=i
                while ii%self.p==0:
                    ii//=self.p
                    self.cnt[i]+=1
                self.factorial.append(self.factorial[-1]*ii%self.mod)
        self.factorial_inve=[None]*(N+1)
        self.factorial_inve[-1]=self.Pow(self.factorial[-1],-1)
        for i in range(N-1,-1,-1):
            ii=i+1
            while ii%self.p==0:
                ii//=self.p
            self.factorial_inve[i]=(self.factorial_inve[i+1]*ii)%self.mod

    def Build_Inverse(self,N):
        self.inverse=[None]*(N+1)
        assert self.p>N
        self.inverse[1]=1
        for n in range(2,N+1):
            if n%self.p==0:
                continue
            a,b=divmod(self.mod,n)
            self.inverse[n]=(-a*self.inverse[b])%self.mod
    
    def Inverse(self,n):
        return self.inverse[n]

    def Fact(self,N):
        if N<0:
            return 0
        retu=self.factorial[N]
        if self.e!=None and self.cnt[N]:
            retu*=pow(self.p,self.cnt[N],self.mod)%self.mod
            retu%=self.mod
        return retu

    def Fact_Inve(self,N):
        if self.e!=None and self.cnt[N]:
            return None
        return self.factorial_inve[N]

    def Comb(self,N,K,divisible_count=False):
        if K<0 or K>N:
            return 0
        retu=self.factorial[N]*self.factorial_inve[K]%self.mod*self.factorial_inve[N-K]%self.mod
        if self.e!=None:
            cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K]
            if divisible_count:
                return retu,cnt
            else:
                retu*=pow(self.p,cnt,self.mod)
                retu%=self.mod
        return retu

def Primitive_Root(p):
    if p==2:
        return 1
    if p==167772161:
        return 3
    if p==469762049:
        return 3
    if p==754974721:
        return 11
    if p==998244353:
        return 3
    if p==10**9+7:
        return 5
    divisors=[2]
    pp=(p-1)//2
    while pp%2==0:
        pp//=2
    for d in range(3,pp+1,2):
        if d**2>pp:
            break
        if pp%d==0:
            divisors.append(d)
            while pp%d==0:
                pp//=d
    if pp>1:
        divisors.append(pp)
    primitive_root=2
    while True:
        for d in divisors:
            if pow(primitive_root,(p-1)//d,p)==1:
                break
        else:
            return primitive_root
        primitive_root+=1

def NTT(polynomial,T):
    if mod==998244353:
        prim_root=3
        prim_root_inve=332748118
    else:
        prim_root=Primitive_Root(mod)
        prim_root_inve=MOD(mod).Pow(prim_root,-1)
    def DFT(polynomial,n,inverse=False):
        if inverse:
            for bit in range(1,n+1):
                a=1<<bit-1
                U=[1]
                x=pow(prim_root,mod-1>>bit,mod)
                for _ in range(a):
                    U.append(U[-1]*x%mod)
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t]*U[j])%mod,(polynomial[s]-polynomial[t]*U[j])%mod
            x=pow((mod+1)//2,n,mod)
            for i in range(1<<n):
                polynomial[i]*=x
                polynomial[i]%=mod
        else:
            for bit in range(n,0,-1):
                a=1<<bit-1
                U=[1]
                x=pow(prim_root_inve,mod-1>>bit,mod)
                for _ in range(a-1):
                    U.append(U[-1]*x%mod)
                for i in range(1<<n-bit):
                    for j in range(a):
                        s=i*2*a+j
                        t=s+a
                        polynomial[s],polynomial[t]=(polynomial[s]+polynomial[t])%mod,U[j]*(polynomial[s]-polynomial[t])%mod
    n0=X+1
    n1=Y+1
    polynomial=[polynomial[i]+[0]*((1<<n1)-len(polynomial[0])) for i in range(len(polynomial))]+[[0]*(1<<n1) for i in range((1<<n0)-len(polynomial))]
    for i in range(1<<n0):
        DFT(polynomial[i],n1)
    polynomial=[[polynomial[i][j] for i in range(1<<n0)] for j in range(1<<n1)]
    for j in range(1<<n1):
        DFT(polynomial[j],n0)
    ntt=[[pow(polynomial[j][i],T,mod) for i in range(1<<n0)] for j in range(1<<n1)]
    for j in range(1<<n1):
        DFT(ntt[j],n0,inverse=True)
    ntt=[[ntt[j][i] for j in range(1<<n1)] for i in range(1<<n0)]
    for i in range(1<<n0):
        DFT(ntt[i],n1,inverse=True)
    return ntt


mod=998244353
X,Y,T,a,b,c,d=map(int,readline().split())
a-=1;b-=1;c-=1;d-=1
poly=[[0]*(1<<Y+1) for x in range(1<<X+1)]
for x in (1,0,-1):
    for y in (1,0,-1):
        if 0 in (x,y):
            poly[x][y]=1
poly=NTT(poly,T)
ans=(poly[(a-c)%(1<<X+1)][(b-d)%(1<<Y+1)]+poly[(a+c+2)%(1<<X+1)][(b+d+2)%(1<<Y+1)]-poly[(a+c+2)%(1<<X+1)][(b-d)%(1<<Y+1)]-poly[(a-c)%(1<<X+1)][(b+d+2)%(1<<Y+1)])%mod
print(ans)
0