結果
問題 | No.2626 Similar But Different Name |
ユーザー | PNJ |
提出日時 | 2024-02-09 23:27:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,747 ms / 3,000 ms |
コード長 | 11,106 bytes |
コンパイル時間 | 220 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 266,320 KB |
最終ジャッジ日時 | 2024-09-28 16:35:16 |
合計ジャッジ時間 | 46,758 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
56,204 KB |
testcase_01 | AC | 42 ms
55,360 KB |
testcase_02 | AC | 37 ms
55,864 KB |
testcase_03 | AC | 38 ms
56,620 KB |
testcase_04 | AC | 38 ms
56,244 KB |
testcase_05 | AC | 45 ms
63,056 KB |
testcase_06 | AC | 44 ms
63,312 KB |
testcase_07 | AC | 66 ms
72,108 KB |
testcase_08 | AC | 65 ms
72,496 KB |
testcase_09 | AC | 65 ms
72,040 KB |
testcase_10 | AC | 130 ms
78,176 KB |
testcase_11 | AC | 125 ms
78,060 KB |
testcase_12 | AC | 114 ms
77,780 KB |
testcase_13 | AC | 126 ms
78,240 KB |
testcase_14 | AC | 129 ms
78,556 KB |
testcase_15 | AC | 128 ms
78,240 KB |
testcase_16 | AC | 124 ms
78,192 KB |
testcase_17 | AC | 128 ms
78,264 KB |
testcase_18 | AC | 2,747 ms
266,256 KB |
testcase_19 | AC | 693 ms
153,936 KB |
testcase_20 | AC | 682 ms
152,996 KB |
testcase_21 | AC | 711 ms
157,260 KB |
testcase_22 | AC | 2,467 ms
245,872 KB |
testcase_23 | AC | 2,398 ms
249,152 KB |
testcase_24 | AC | 2,286 ms
227,396 KB |
testcase_25 | AC | 2,394 ms
237,172 KB |
testcase_26 | AC | 2,425 ms
249,108 KB |
testcase_27 | AC | 2,467 ms
248,532 KB |
testcase_28 | AC | 2,425 ms
244,372 KB |
testcase_29 | AC | 2,353 ms
232,260 KB |
testcase_30 | AC | 2,374 ms
238,672 KB |
testcase_31 | AC | 2,410 ms
244,276 KB |
testcase_32 | AC | 2,434 ms
249,168 KB |
testcase_33 | AC | 2,461 ms
249,204 KB |
testcase_34 | AC | 2,558 ms
230,284 KB |
testcase_35 | AC | 2,475 ms
244,664 KB |
testcase_36 | AC | 2,345 ms
230,396 KB |
testcase_37 | AC | 2,721 ms
266,320 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] class string: def sa_is(s,upper): n=len(s) if n==0: return [] if n==1: return [0] if n==2: if (s[0]<s[1]): return [0,1] else: return [1,0] sa=[0]*n ls=[0]*n for i in range(n-2,-1,-1): ls[i]=ls[i+1] if (s[i]==s[i+1]) else (s[i]<s[i+1]) sum_l=[0]*(upper+1) sum_s=[0]*(upper+1) for i in range(n): if not(ls[i]): sum_s[s[i]]+=1 else: sum_l[s[i]+1]+=1 for i in range(upper+1): sum_s[i]+=sum_l[i] if i<upper: sum_l[i+1]+=sum_s[i] def induce(lms): for i in range(n): sa[i]=-1 buf=sum_s[:] for d in lms: if d==n: continue sa[buf[s[d]]]=d buf[s[d]]+=1 buf=sum_l[:] sa[buf[s[n-1]]]=n-1 buf[s[n-1]]+=1 for i in range(n): v=sa[i] if v>=1 and not(ls[v-1]): sa[buf[s[v-1]]]=v-1 buf[s[v-1]]+=1 buf=sum_l[:] for i in range(n-1,-1,-1): v=sa[i] if v>=1 and ls[v-1]: buf[s[v-1]+1]-=1 sa[buf[s[v-1]+1]]=v-1 lms_map=[-1]*(n+1) m=0 for i in range(1,n): if not(ls[i-1]) and ls[i]: lms_map[i]=m m+=1 lms=[] for i in range(1,n): if not(ls[i-1]) and ls[i]: lms.append(i) induce(lms) if m: sorted_lms=[] for v in sa: if lms_map[v]!=-1: sorted_lms.append(v) rec_s=[0]*m rec_upper=0 rec_s[lms_map[sorted_lms[0]]]=0 for i in range(1,m): l=sorted_lms[i-1] r=sorted_lms[i] end_l=lms[lms_map[l]+1] if (lms_map[l]+1<m) else n end_r=lms[lms_map[r]+1] if (lms_map[r]+1<m) else n same=True if end_l-l!=end_r-r: same=False else: while(l<end_l): if s[l]!=s[r]: break l+=1 r+=1 if (l==n) or (s[l]!=s[r]): same=False if not(same): rec_upper+=1 rec_s[lms_map[sorted_lms[i]]]=rec_upper rec_sa=string.sa_is(rec_s,rec_upper) for i in range(m): sorted_lms[i]=lms[rec_sa[i]] induce(sorted_lms) return sa def suffix_array_upper(s,upper): assert 0<=upper for d in s: assert 0<=d and d<=upper return string.sa_is(s,upper) def suffix_array(s): n=len(s) if type(s)==str: s2=[ord(i) for i in s] return string.sa_is(s2,255) else: idx=list(range(n)) idx.sort(key=lambda x:s[x]) s2=[0]*n now=0 for i in range(n): if (i& s[idx[i-1]]!=s[idx[i]]): now+=1 s2[idx[i]]=now return string.sa_is(s2,now) def lcp_array(s,sa): n=len(s) assert n>=1 rnk=[0]*n for i in range(n): rnk[sa[i]]=i lcp=[0]*(n-1) h=0 for i in range(n): if h>0: h-=1 if rnk[i]==0: continue j=sa[rnk[i]-1] while(j+h<n and i+h<n): if s[j+h]!=s[i+h]: break h+=1 lcp[rnk[i]-1]=h return lcp N,M,K = map(int,input().split()) P,PP = [0 for i in range(N)],[0 for i in range(N)] Q,QQ = [0 for i in range(M)],[0 for i in range(M)] S = input() S = [S[i] for i in range(N)] for i in range(N): if ord(S[i]) < 97: P[i] = 1 S[i] = ord(S[i]) - 65 else: PP[i] = 1 S[i] = ord(S[i]) - 97 T = input() T = [T[i] for i in range(M)] for i in range(M): if ord(T[i]) < 97: QQ[i] = 1 T[i] = ord(T[i]) - 65 else: Q[i] = 1 T[i] = ord(T[i]) - 97 P = P[::-1] PP = PP[::-1] ans = [0 for i in range(N)] b = 100 mod = 2**61 - 1 for i in range(N): S[i] *= pow(b,i,mod) S[i] %= mod for i in range(M): T[i] *= pow(b,i,mod) T[i] %= mod TT = sum(T) % mod SS = 0 for i in range(M): SS += S[i] SS %= mod if SS == TT: ans[0] = 1 for i in range(1,N-M+1): SS -= S[i-1] SS += S[i+M-1] SS %= mod TT *= b TT %= mod if SS == TT: ans[i] = 1 CONV = FFT(998244353) F = CONV.convolution(P,Q) G = CONV.convolution(PP,QQ) for i in range(N): n = N - 1 - i if F[n] + G[n] > K: ans[i] = 0 elif F[n] + G[n] == 0: ans[i] = 0 print(sum(ans))