Submission #44125453
Source Code Expand
#include<bits/stdc++.h>
#define ld long double
#define ui unsigned int
#define ull unsigned long long
#define int long long
#define eb emplace_back
#define pb pop_back
#define ins insert
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define power(x) ((x)*(x))
#define gcd(x,y) (__gcd((x),(y)))
#define lcm(x,y) ((x)*(y)/gcd((x),(y)))
#define lg(x,y) (__lg((x),(y)))
#pragma GCC optimize(2)
using namespace std;
namespace FastIO
{
template<typename T=int> inline T read()
{
T s=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) s=(s*10)+(c^48),c=getchar();
return s*w;
}
template<typename T> inline void read(T &s)
{
s=0; int w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) s=(s*10)+(c^48),c=getchar();
s=s*w;
}
template<typename T,typename... Args> inline void read(T &x,Args &...args)
{
read(x),read(args...);
}
template<typename T> inline void write(T x,char ch)
{
if(x<0) x=-x,putchar('-');
static char stk[25]; int top=0;
do {stk[top++]=x%10+'0',x/=10;} while(x);
while(top) putchar(stk[--top]);
putchar(ch);
return;
}
}
using namespace FastIO;
namespace MTool
{
#define TA template<typename T,typename... Args>
#define TT template<typename T>
static const int Mod=998244353;
TT inline void Swp(T &a,T &b) {T t=a;a=b;b=t;}
TT inline void cmax(T &a,T b) {a=max(a,b);}
TT inline void cmin(T &a,T b) {a=min(a,b);}
TA inline void cmax(T &a,T b,Args... args) {a=max({a,b,args...});}
TA inline void cmin(T &a,T b,Args... args) {a=min({a,b,args...});}
TT inline void Madd(T &a,T b) {a=a+b>Mod?a+b-Mod:a+b;}
TT inline void Mdel(T &a,T b) {a=a-b<0?a-b+Mod:a-b;}
TT inline void Mmul(T &a,T b) {a=a*b%Mod;}
TT inline void Mmod(T &a) {a=(a%Mod+Mod)%Mod;}
TT inline T Cadd(T a,T b) {return a+b>=Mod?a+b-Mod:a+b;}
TT inline T Cdel(T a,T b) {return a-b<0?a-b+Mod:a-b;}
TT inline T Cmul(T a,T b) {return a*b%Mod;}
TT inline T Cmod(T a) {return (a%Mod+Mod)%Mod;}
TA inline void Madd(T &a,T b,Args... args) {Madd(a,Cadd(b,args...));}
TA inline void Mdel(T &a,T b,Args... args) {Mdel(a,Cadd(b,args...));}
TA inline void Mmul(T &a,T b,Args... args) {Mmul(a,Cmul(b,args...));}
TA inline T Cadd(T a,T b,Args... args) {return Cadd(Cadd(a,b),args...);}
TA inline T Cdel(T a,T b,Args... args) {return Cdel(Cdel(a,b),args...);}
TA inline T Cmul(T a,T b,Args... args) {return Cmul(Cmul(a,b),args...);}
TT inline T qpow(T a,T b) {int res=1; while(b) {if(b&1) Mmul(res,a); Mmul(a,a); b>>=1;} return res;}
TT inline T qmul(T a,T b) {int res=0; while(b) {if(b&1) Madd(res,a); Madd(a,a); b>>=1;} return res;}
TT inline T spow(T a,T b) {int res=1; while(b) {if(b&1) res=qmul(res,a); a=qmul(a,a); b>>=1;} return res;}
TT inline void exgcd(T A,T B,T &X,T &Y) {if(!B) return X=1,Y=0,void(); exgcd(B,A%B,Y,X),Y-=X*(A/B);}
TT inline T Ginv(T x) {T A=0,B=0; exgcd(x,Mod,A,B); return Cmod(A);}
#undef TT
#undef TA
}
using namespace MTool;
inline void file()
{
freopen(".in","r",stdin);
freopen(".out","w",stdout);
return;
}
bool Mbe;
namespace LgxTpre
{
static const int MAX=5000010;
static const int inf=2147483647;
static const int INF=4557430888798830399;
static const int mod=1e9+7;
static const int bas=131;
int n,m;
char a[MAX],b[MAX];
namespace FFTmatch
{
static const double PI=acos(-1);
static const double eps=0.5;
struct Complex
{
double x,y;
Complex(double X=0.0,double Y=0.0):x(X),y(Y) {}
inline friend Complex operator + (Complex a,Complex b) {return Complex(a.x+b.x,a.y+b.y);}
inline friend Complex operator - (Complex a,Complex b) {return Complex(a.x-b.x,a.y-b.y);}
inline friend Complex operator * (Complex a,Complex b) {return Complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x);}
template<typename T> inline friend Complex operator / (Complex a,T b) {return Complex(a.x/b,a.y/b);}
};
typedef vector<Complex> VC;
typedef vector<int> VI;
int rev[MAX],revnow;
inline int Sup(int n) {int k=0; while((1<<k)<n) ++k; return k;}
inline void Rea(int k) {if(k==revnow) return; rev[0]=0; for(int i=1;i<=(1<<k);++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));}
inline void DFT(VC &F,int K,int typ)
{
int N=1<<K;
for(int i=0;i<N;++i) if(rev[i]>i) swap(F[i],F[rev[i]]);
for(int len=2,l=1;len<=N;len<<=1,l<<=1)
{
Complex stp(cos(2*PI/len),sin(typ*2*PI/len));
for(int st=0;st<N;st+=len)
{
Complex omega(1,0),U,V;
for(int i=0;i<l;++i)
U=F[st+i],V=omega*F[st+i+l],
F[st+i]=U+V,F[st+i+l]=U-V,
omega=omega*stp;
}
}
if(typ==-1) for(int i=0;i<N;++i) F[i]=F[i]/N;
}
inline VI solve(char *a,char *b)
{
auto get=[](char c)->int
{
if(c=='_') return 0;
if(c=='.') return 1;
if(c>='A'&&c<='Z') return c-'A'+2;
return c-'a'+28;
};
VI A,B,ans; VC F,G,H;
int n=strlen(a),m=strlen(b),N=n+m-1;
for(int i=1;i<n;++i) B.eb(1);
for(int i=0;i<m;++i) B.eb(get(b[i]));
for(int i=1;i<n;++i) B.eb(1);
m=B.size(),N=n+m-1;
for(int i=0;i<n;++i) A.eb(get(a[i]));
int K=Sup(N); Rea(K);
F.resize(1<<K),G.resize(1<<K),H.resize(1<<K);
reverse(A.begin(),A.end());
for(int i=n;i<(1<<K);++i) A.eb(0);
for(int i=m;i<(1<<K);++i) B.eb(0);
for(int i=0;i<(1<<K);++i) F[i]=Complex(A[i]*A[i]*A[i],0),G[i]=Complex(B[i],0);
DFT(F,K,1),DFT(G,K,1);
for(int i=0;i<(1<<K);++i) H[i]=H[i]+F[i]*G[i];
for(int i=0;i<(1<<K);++i) F[i]=Complex(A[i],0),G[i]=Complex(B[i]*B[i]*B[i],0);
DFT(F,K,1),DFT(G,K,1);
for(int i=0;i<(1<<K);++i) H[i]=H[i]+F[i]*G[i];
for(int i=0;i<(1<<K);++i) F[i]=Complex(A[i]*A[i],0),G[i]=Complex(B[i]*B[i],0);
DFT(F,K,1),DFT(G,K,1);
for(int i=0;i<(1<<K);++i) H[i]=H[i]-F[i]*G[i]*Complex(2,0);
DFT(H,K,-1);
for(int i=n-1;i<m;++i) if(fabs(H[i].x)<eps) ans.eb(i-n+2);
return ans;
}
}
inline void mian()
{
scanf("%lld%lld%s%s",&n,&m,a,b);
write(FFTmatch::solve(b,a).size(),'\n');
return;
}
}
bool Med;
signed main()
{
// file();
fprintf(stderr,"%.3lf MB\n",abs(&Med-&Mbe)/1048576.0);
int Tbe=clock();
LgxTpre::mian();
int Ted=clock();
cerr<<1e3*(Ted-Tbe)/CLOCKS_PER_SEC<<" ms\n";
return (0-0);
}
Submission Info
Submission Time
2023-07-31 10:05:29+0900
Task
Ex - Marquee
User
MyYouthsoSTRONG
Language
C++ (GCC 9.2.1)
Score
600
Code Size
7036 Byte
Status
AC
Exec Time
956 ms
Memory
164692 KiB
Compile Error
./Main.cpp: In function ‘void LgxTpre::mian()’:
./Main.cpp:183:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
183 | scanf("%lld%lld%s%s",&n,&m,a,b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
600 / 600
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, random_50.txt, random_51.txt, random_52.txt, random_53.txt, random_54.txt, random_55.txt, random_56.txt, random_57.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name
Status
Exec Time
Memory
random_01.txt
AC
938 ms
164468 KiB
random_02.txt
AC
194 ms
44260 KiB
random_03.txt
AC
416 ms
84348 KiB
random_04.txt
AC
427 ms
81392 KiB
random_05.txt
AC
404 ms
79120 KiB
random_06.txt
AC
405 ms
77704 KiB
random_07.txt
AC
405 ms
78480 KiB
random_08.txt
AC
188 ms
40420 KiB
random_09.txt
AC
926 ms
151448 KiB
random_10.txt
AC
413 ms
79476 KiB
random_11.txt
AC
412 ms
79068 KiB
random_12.txt
AC
191 ms
42224 KiB
random_13.txt
AC
954 ms
151620 KiB
random_14.txt
AC
189 ms
40508 KiB
random_15.txt
AC
408 ms
79040 KiB
random_16.txt
AC
411 ms
78272 KiB
random_17.txt
AC
939 ms
151588 KiB
random_18.txt
AC
421 ms
77852 KiB
random_19.txt
AC
413 ms
78424 KiB
random_20.txt
AC
94 ms
22020 KiB
random_21.txt
AC
408 ms
78844 KiB
random_22.txt
AC
414 ms
78348 KiB
random_23.txt
AC
406 ms
78856 KiB
random_24.txt
AC
941 ms
151492 KiB
random_25.txt
AC
414 ms
78072 KiB
random_26.txt
AC
193 ms
40480 KiB
random_27.txt
AC
424 ms
78512 KiB
random_28.txt
AC
421 ms
78612 KiB
random_29.txt
AC
410 ms
84664 KiB
random_30.txt
AC
425 ms
84224 KiB
random_31.txt
AC
922 ms
164408 KiB
random_32.txt
AC
30 ms
8208 KiB
random_33.txt
AC
918 ms
151496 KiB
random_34.txt
AC
402 ms
78612 KiB
random_35.txt
AC
915 ms
151660 KiB
random_36.txt
AC
93 ms
22396 KiB
random_37.txt
AC
423 ms
78312 KiB
random_38.txt
AC
403 ms
77688 KiB
random_39.txt
AC
425 ms
85204 KiB
random_40.txt
AC
434 ms
77596 KiB
random_41.txt
AC
413 ms
78692 KiB
random_42.txt
AC
409 ms
77556 KiB
random_43.txt
AC
946 ms
164692 KiB
random_44.txt
AC
195 ms
44132 KiB
random_45.txt
AC
956 ms
151580 KiB
random_46.txt
AC
430 ms
77416 KiB
random_47.txt
AC
917 ms
151528 KiB
random_48.txt
AC
410 ms
77436 KiB
random_49.txt
AC
8 ms
3672 KiB
random_50.txt
AC
2 ms
3876 KiB
random_51.txt
AC
2 ms
3880 KiB
random_52.txt
AC
921 ms
151592 KiB
random_53.txt
AC
950 ms
151536 KiB
random_54.txt
AC
943 ms
151380 KiB
random_55.txt
AC
92 ms
22464 KiB
random_56.txt
AC
190 ms
40420 KiB
random_57.txt
AC
437 ms
77312 KiB
sample_01.txt
AC
2 ms
4324 KiB
sample_02.txt
AC
2 ms
4140 KiB
sample_03.txt
AC
2 ms
4192 KiB
sample_04.txt
AC
2 ms
3688 KiB