結果
問題 | No.2626 Similar But Different Name |
ユーザー | ゼット |
提出日時 | 2024-02-09 22:29:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,662 ms / 3,000 ms |
コード長 | 6,957 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 178,512 KB |
最終ジャッジ日時 | 2024-09-28 15:43:49 |
合計ジャッジ時間 | 35,653 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
54,232 KB |
testcase_01 | AC | 35 ms
55,516 KB |
testcase_02 | AC | 36 ms
54,708 KB |
testcase_03 | AC | 35 ms
55,280 KB |
testcase_04 | AC | 39 ms
55,168 KB |
testcase_05 | AC | 42 ms
62,072 KB |
testcase_06 | AC | 41 ms
61,708 KB |
testcase_07 | AC | 107 ms
77,900 KB |
testcase_08 | AC | 109 ms
77,976 KB |
testcase_09 | AC | 105 ms
78,088 KB |
testcase_10 | AC | 113 ms
77,952 KB |
testcase_11 | AC | 109 ms
77,980 KB |
testcase_12 | AC | 109 ms
77,764 KB |
testcase_13 | AC | 108 ms
77,776 KB |
testcase_14 | AC | 109 ms
77,992 KB |
testcase_15 | AC | 112 ms
77,888 KB |
testcase_16 | AC | 108 ms
77,880 KB |
testcase_17 | AC | 108 ms
77,996 KB |
testcase_18 | AC | 1,588 ms
174,920 KB |
testcase_19 | AC | 1,642 ms
171,436 KB |
testcase_20 | AC | 1,640 ms
171,384 KB |
testcase_21 | AC | 1,647 ms
171,452 KB |
testcase_22 | AC | 1,623 ms
171,364 KB |
testcase_23 | AC | 1,658 ms
176,564 KB |
testcase_24 | AC | 1,642 ms
170,880 KB |
testcase_25 | AC | 1,642 ms
170,736 KB |
testcase_26 | AC | 1,644 ms
171,012 KB |
testcase_27 | AC | 1,643 ms
170,656 KB |
testcase_28 | AC | 1,659 ms
174,812 KB |
testcase_29 | AC | 1,623 ms
171,796 KB |
testcase_30 | AC | 1,614 ms
171,104 KB |
testcase_31 | AC | 1,629 ms
171,864 KB |
testcase_32 | AC | 1,630 ms
170,888 KB |
testcase_33 | AC | 1,645 ms
171,572 KB |
testcase_34 | AC | 1,662 ms
171,868 KB |
testcase_35 | AC | 1,642 ms
178,512 KB |
testcase_36 | AC | 1,627 ms
170,696 KB |
testcase_37 | AC | 1,556 ms
175,728 KB |
ソースコード
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 rank2=0 root=[] iroot=[] rate2=[] irate2=[] rate3=[] irate3=[] def __init__(self,MOD): self.mod=MOD self.g=self.primitive_root_constexpr(self.mod) self.rank2=self.bsf(self.mod-1) self.root=[0 for i in range(self.rank2+1)] self.iroot=[0 for i in range(self.rank2+1)] self.rate2=[0 for i in range(self.rank2)] self.irate2=[0 for i in range(self.rank2)] self.rate3=[0 for i in range(self.rank2-1)] self.irate3=[0 for i in range(self.rank2-1)] self.root[self.rank2]=pow(self.g,(self.mod-1)>>self.rank2,self.mod) self.iroot[self.rank2]=pow(self.root[self.rank2],self.mod-2,self.mod) for i in range(self.rank2-1,-1,-1): self.root[i]=(self.root[i+1]**2)%self.mod self.iroot[i]=(self.iroot[i+1]**2)%self.mod prod=1;iprod=1 for i in range(self.rank2-1): self.rate2[i]=(self.root[i+2]*prod)%self.mod self.irate2[i]=(self.iroot[i+2]*iprod)%self.mod prod=(prod*self.iroot[i+2])%self.mod iprod=(iprod*self.root[i+2])%self.mod prod=1;iprod=1 for i in range(self.rank2-2): self.rate3[i]=(self.root[i+3]*prod)%self.mod self.irate3[i]=(self.iroot[i+3]*iprod)%self.mod prod=(prod*self.iroot[i+3])%self.mod iprod=(iprod*self.root[i+3])%self.mod def butterfly(self,a): n=len(a) h=(n-1).bit_length() LEN=0 while(LEN<h): if (h-LEN==1): p=1<<(h-LEN-1) rot=1 for s in range(1<<LEN): offset=s<<(h-LEN) for i in range(p): l=a[i+offset] r=a[i+offset+p]*rot a[i+offset]=(l+r)%self.mod a[i+offset+p]=(l-r)%self.mod rot*=self.rate2[(~s & -~s).bit_length()-1] rot%=self.mod LEN+=1 else: p=1<<(h-LEN-2) rot=1 imag=self.root[2] for s in range(1<<LEN): rot2=(rot*rot)%self.mod rot3=(rot2*rot)%self.mod offset=s<<(h-LEN) for i in range(p): a0=a[i+offset] a1=a[i+offset+p]*rot a2=a[i+offset+2*p]*rot2 a3=a[i+offset+3*p]*rot3 a1na3imag=(a1-a3)%self.mod*imag a[i+offset]=(a0+a2+a1+a3)%self.mod a[i+offset+p]=(a0+a2-a1-a3)%self.mod a[i+offset+2*p]=(a0-a2+a1na3imag)%self.mod a[i+offset+3*p]=(a0-a2-a1na3imag)%self.mod rot*=self.rate3[(~s & -~s).bit_length()-1] rot%=self.mod LEN+=2 def butterfly_inv(self,a): n=len(a) h=(n-1).bit_length() LEN=h while(LEN): if (LEN==1): p=1<<(h-LEN) irot=1 for s in range(1<<(LEN-1)): offset=s<<(h-LEN+1) for i in range(p): l=a[i+offset] r=a[i+offset+p] a[i+offset]=(l+r)%self.mod a[i+offset+p]=(l-r)*irot%self.mod irot*=self.irate2[(~s & -~s).bit_length()-1] irot%=self.mod LEN-=1 else: p=1<<(h-LEN) irot=1 iimag=self.iroot[2] for s in range(1<<(LEN-2)): irot2=(irot*irot)%self.mod irot3=(irot*irot2)%self.mod offset=s<<(h-LEN+2) for i in range(p): a0=a[i+offset] a1=a[i+offset+p] a2=a[i+offset+2*p] a3=a[i+offset+3*p] a2na3iimag=(a2-a3)*iimag%self.mod a[i+offset]=(a0+a1+a2+a3)%self.mod a[i+offset+p]=(a0-a1+a2na3iimag)*irot%self.mod a[i+offset+2*p]=(a0+a1-a2-a3)*irot2%self.mod a[i+offset+3*p]=(a0-a1-a2na3iimag)*irot3%self.mod irot*=self.irate3[(~s & -~s).bit_length()-1] irot%=self.mod LEN-=2 def convolution(self,a,b): n=len(a);m=len(b) if not(a) or not(b): return [] if min(n,m)<=40: 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=[(a[i]*b[i])%self.mod for i in range(z)] 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] mod=67280421310721 N,M,K=map(int,input().split()) S=input() T=input() hash1=[0]*N hash2=[0]*N x100=[1]*(N+1) for i in range(1,N+1): x100[i]=x100[i-1]*100 x100[i]%=mod u1=[0]*N u2=[0]*N v1=[0]*N v2=[0]*N for i in range(N): if S[i].islower(): x=ord(S[i])-ord('a')+1 u1[i]=1 if S[i].isupper(): x=ord(S[i])-ord('A')+1 u2[i]=1 hash1[i]=hash1[i-1]*100+x hash1[i]%=mod for i in range(M): if T[i].islower(): x=ord(T[i])-ord('a')+1 v1[M-1-i]=1 else: x=ord(T[i])-ord('A')+1 v2[M-1-i]=1 hash2[i]=hash2[i-1]*100+x hash2[i]%=mod mod2=998244353 Z=FFT(mod2) k1=Z.convolution(u1,v2) k2=Z.convolution(u2,v1) result=0 for i in range(N-M+1): w=hash1[i+M-1] if i>0: w-=hash1[i-1]*x100[M] w%=mod if w==hash2[M-1]: ans=k1[i+M-1]+k2[i+M-1] if 1<=ans<=K: result+=1 print(result)