結果

問題 No.1241 Eternal Tours
ユーザー vwxyzvwxyz
提出日時 2023-11-18 18:47:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,256 ms / 6,000 ms
コード長 5,878 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 186,324 KB
最終ジャッジ日時 2024-09-26 05:54:24
合計ジャッジ時間 45,137 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,760 KB
testcase_01 AC 46 ms
54,016 KB
testcase_02 AC 697 ms
117,852 KB
testcase_03 AC 94 ms
76,160 KB
testcase_04 AC 65 ms
65,024 KB
testcase_05 AC 49 ms
54,172 KB
testcase_06 AC 48 ms
53,760 KB
testcase_07 AC 51 ms
55,168 KB
testcase_08 AC 77 ms
70,016 KB
testcase_09 AC 65 ms
65,444 KB
testcase_10 AC 78 ms
70,016 KB
testcase_11 AC 75 ms
69,504 KB
testcase_12 AC 48 ms
54,784 KB
testcase_13 AC 64 ms
64,896 KB
testcase_14 AC 1,154 ms
100,440 KB
testcase_15 AC 48 ms
54,144 KB
testcase_16 AC 381 ms
82,840 KB
testcase_17 AC 2,922 ms
186,324 KB
testcase_18 AC 2,306 ms
130,048 KB
testcase_19 AC 2,361 ms
134,820 KB
testcase_20 AC 110 ms
76,416 KB
testcase_21 AC 164 ms
77,900 KB
testcase_22 AC 2,618 ms
159,508 KB
testcase_23 AC 173 ms
77,568 KB
testcase_24 AC 44 ms
53,760 KB
testcase_25 AC 76 ms
69,632 KB
testcase_26 AC 45 ms
53,504 KB
testcase_27 AC 45 ms
53,504 KB
testcase_28 AC 1,190 ms
117,692 KB
testcase_29 AC 1,206 ms
117,892 KB
testcase_30 AC 1,452 ms
117,648 KB
testcase_31 AC 987 ms
97,920 KB
testcase_32 AC 2,952 ms
186,208 KB
testcase_33 AC 2,848 ms
173,012 KB
testcase_34 AC 1,988 ms
117,632 KB
testcase_35 AC 1,940 ms
117,632 KB
testcase_36 AC 49 ms
53,632 KB
testcase_37 AC 72 ms
66,304 KB
testcase_38 AC 3,256 ms
172,756 KB
testcase_39 AC 2,858 ms
149,216 KB
testcase_40 AC 2,383 ms
117,732 KB
testcase_41 AC 2,451 ms
186,196 KB
testcase_42 AC 2,040 ms
148,960 KB
testcase_43 AC 1,508 ms
117,876 KB
権限があれば一括ダウンロードができます

ソースコード

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