結果

問題 No.2626 Similar But Different Name
ユーザー TairitsuMeowTairitsuMeow
提出日時 2024-02-09 22:51:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,271 ms / 3,000 ms
コード長 2,785 bytes
コンパイル時間 1,679 ms
コンパイル使用メモリ 173,936 KB
実行使用メモリ 356,964 KB
最終ジャッジ日時 2024-02-09 22:52:17
合計ジャッジ時間 28,244 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
330,568 KB
testcase_01 AC 120 ms
330,568 KB
testcase_02 AC 119 ms
330,568 KB
testcase_03 AC 118 ms
330,568 KB
testcase_04 AC 149 ms
330,568 KB
testcase_05 AC 120 ms
330,568 KB
testcase_06 AC 121 ms
330,568 KB
testcase_07 AC 121 ms
330,600 KB
testcase_08 AC 121 ms
330,600 KB
testcase_09 AC 146 ms
330,600 KB
testcase_10 AC 122 ms
330,632 KB
testcase_11 AC 123 ms
330,632 KB
testcase_12 AC 120 ms
330,600 KB
testcase_13 AC 122 ms
330,632 KB
testcase_14 AC 123 ms
330,632 KB
testcase_15 AC 122 ms
330,632 KB
testcase_16 AC 148 ms
330,632 KB
testcase_17 AC 122 ms
330,632 KB
testcase_18 AC 1,224 ms
356,964 KB
testcase_19 AC 621 ms
350,820 KB
testcase_20 AC 600 ms
350,820 KB
testcase_21 AC 647 ms
350,820 KB
testcase_22 AC 1,198 ms
354,916 KB
testcase_23 AC 1,203 ms
354,916 KB
testcase_24 AC 1,227 ms
352,868 KB
testcase_25 AC 1,202 ms
354,916 KB
testcase_26 AC 1,176 ms
354,916 KB
testcase_27 AC 1,206 ms
354,916 KB
testcase_28 AC 1,194 ms
354,916 KB
testcase_29 AC 1,217 ms
352,868 KB
testcase_30 AC 1,198 ms
354,916 KB
testcase_31 AC 1,231 ms
354,916 KB
testcase_32 AC 1,169 ms
354,916 KB
testcase_33 AC 1,202 ms
354,916 KB
testcase_34 AC 1,234 ms
352,868 KB
testcase_35 AC 1,271 ms
354,916 KB
testcase_36 AC 1,208 ms
352,868 KB
testcase_37 AC 1,264 ms
356,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2626 Similar But Different Name
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2626
// Memory Limit: 512 MB
// Time Limit: 3000 ms

#include<bits/stdc++.h>
#define debug(x) cerr<<(#x)<<" "<<(x)<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll,ll>
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define per(i,a,b) for(ll i=(a);i>=(b);--i)
using namespace std;
bool Mbe; 
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
const ll N=4e6+9;
const ull B=131;
ll n,m,k,ans[N],r[N],f[N],g[N];
char s[N],t[N];
ull hs[N],ht[N],pw[N],hs2[N];
struct Comp{
	ld x,y;
	Comp(ld a=0,ld b=0){x=a,y=b;}
};
inline Comp operator+(const Comp&a,const Comp&b){return Comp(a.x+b.x,a.y+b.y);}
inline Comp operator-(const Comp&a,const Comp&b){return Comp(a.x-b.x,a.y-b.y);}
inline Comp operator*(const Comp&a,const Comp&b){return Comp(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
Comp a[N],b[N]; 
const ld PI=acos(-1.0);
void FFT(Comp*a,ll p,ll sgn){
	rep(i,0,p-1){
		if(i<r[i])swap(a[i],a[r[i]]);
	}
	for(ll mid=2;mid<=p;mid<<=1){
		Comp wn=Comp(cos(2*PI/mid),sin(2*PI/mid)*sgn);
		ll R=mid>>1;
		for(ll j=0;j<p;j+=mid){
			Comp w=Comp(1.0,0.0);
			rep(k,j,j+R-1){
				Comp x=w*a[R+k];
				a[R+k]=a[k]-x,a[k]=a[k]+x;
				w=w*wn;
			}
		}
	}
}
void MUL(ll*f,ll*g,ll n,ll m){
	ll c=0,p=1;
	while(p<=n+m)p*=2,c++;
	rep(i,0,p-1)r[i]=(r[i>>1]>>1)|((i&1)?(p>>1):0);
	rep(i,0,n-1)a[i].x=f[i],a[i].y=0;
	rep(i,n,p-1)a[i].x=0,a[i].y=0;
	rep(i,0,m-1)b[i].x=g[i],b[i].y=0;
	rep(i,m,p-1)b[i].x=0,b[i].y=0;
	FFT(a,p,1);
	FFT(b,p,1);
	rep(i,0,p-1)a[i]=a[i]*b[i];
	FFT(a,p,-1);
	rep(i,0,n+m-1)f[i]=(ll)(a[i].x/p+0.5);
}
ull Hs(ll l,ll r){
	return hs[r]-hs[l-1]*pw[r-l+1];
}
ull Hs2(ll l,ll r){
	return hs2[r]-hs2[l-1]*pw[r-l+1];
}
map<ull,ll>mp;
bool Med;
int main(){
	cerr<<fabs(&Med-&Mbe)/1048576.0<<"MB\n";
	n=read(),m=read(),k=read();
	scanf("%s%s",s,t);
	rep(i,0,n-1)f[i]=islower(s[i])?1:0;
	rep(i,0,m-1)g[i]=islower(t[i])?1:0;
	reverse(g,g+m);
	MUL(f,g,n,m);
	rep(i,m-1,n-1)ans[i]+=f[i];
	memset(f,0,sizeof(f));
	memset(g,0,sizeof(g));
	rep(i,0,n-1)f[i]=isupper(s[i])?1:0;
	rep(i,0,m-1)g[i]=isupper(t[i])?1:0;
	reverse(g,g+m);
	MUL(f,g,n,m);
	pw[0]=1;
	rep(i,1,n)pw[i]=pw[i-1]*B;
	rep(i,m-1,n-1)ans[i]+=f[i];
	hs[0]=tolower(s[0]);
	rep(i,1,n-1)hs[i]=hs[i-1]*B+tolower(s[i]);
	hs2[0]=(islower(s[0]));
	rep(i,1,n-1)hs2[i]=hs2[i-1]*B+(islower(s[i]));
	ht[0]=tolower(t[0]);
	rep(i,1,m-1)ht[i]=ht[i-1]*B+tolower(t[i]);
	ll res=0;
	rep(i,m-1,n-1){
		if(Hs(i-m+1,i)!=ht[m-1])continue;
		if(ans[i]!=m&&ans[i]+k>=m)res++;
	}
	write(res);
	return 0;
}
0