好神啊orz Claris
附上题解传送门:portal
大概就是转换成三段卷积来算。然后大概你要手写complex才能过qaq
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <complex>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 300010
#define pi acos(-1)
typedef complex<double> E;
inline int read(){
int 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;
}
int m,n,mm,nn,L=0,R[N<<2],ans[N];
E a[N<<2],b[N<<2],c[N<<2];
char A[N],B[N];
inline int pow3(int x){return x*x*x;}
inline int pow2(int x){return x*x;}
inline void fft(E *a,int f){
for(int i=0;i<n;++i) if(i<R[i]) swap(a[i],a[R[i]]);
for(int i=1;i<n;i+=i){
E wn(cos(pi/i),f*sin(pi/i));
for(int p=i<<1,j=0;j<n;j+=p){
E w(1,0);
for(int k=0;k<i;++k,w*=wn){
E x=a[j+k],y=w*a[j+k+i];
a[j+k]=x+y;a[j+k+i]=x-y;
}
}
}if(f==-1) for(int i=0;i<n;++i) a[i]/=n;
}
int main(){
freopen("a.in","r",stdin);
mm=read();nn=read();m=nn+nn;for(n=1;n<=m;n+=n) ++L;
for(int i=0;i<n;++i) R[i]=(R[i>>1]>>1)|(i&1)<<L-1;
scanf("%s",A);scanf("%s",B);
for(int i=0;i<mm;++i) a[i]=pow3((A[mm-1-i]=='*'?0:A[mm-1-i]));
for(int i=0;i<nn;++i) b[i]=(B[i]=='*'?0:B[i]);
fft(a,1);fft(b,1);
for(int i=0;i<n;++i) c[i]+=a[i]*b[i];memset(a,0,sizeof(a));memset(b,0,sizeof(b));
for(int i=0;i<mm;++i) a[i]=pow2((A[mm-1-i]=='*'?0:A[mm-1-i]));
for(int i=0;i<nn;++i) b[i]=pow2(B[i]=='*'?0:B[i]);
fft(a,1);fft(b,1);
for(int i=0;i<n;++i) c[i]-=a[i]*b[i]*E(2,0);memset(a,0,sizeof(a));memset(b,0,sizeof(b));
for(int i=0;i<mm;++i) a[i]=(A[mm-1-i]=='*'?0:A[mm-1-i]);
for(int i=0;i<nn;++i) b[i]=pow3(B[i]=='*'?0:B[i]);
fft(a,1);fft(b,1);
for(int i=0;i<n;++i) c[i]+=a[i]*b[i];fft(c,-1);
for(int i=1;i<=nn-mm+1;++i)
if((int)(c[i+mm-1-1].real()+0.5)==0) ans[++ans[0]]=i;
printf("%d\n",ans[0]);
for(int i=1;i<=ans[0];++i) printf("%d ",ans[i]);
return 0;
}