我自己造了些数据没问题,但是全部RE
#include<bits/stdc++.h>
using namespace std;
long long next[1000001];
char s1[1000001],s2[1000001];
int findnext(){
long long j=0,k=-1;
next[0]=-1;
while(j<strlen(s2)){
if(k==-1||s2[j]==s2[k]){
next[++j]=++k;
}
else{
k=next[k];
}
}
}
int main(){
cin>>s1>>s2;
findnext();
long long i=0,j=0;
while(i<strlen(s1)){
if(j==-1||s1[i]==s2[j]){
i++;
j++;
}
else{
j=next[j];
}
if(j==strlen(s2)){
cout<<i-j+1<<endl;
j=next[j];
}
}
for(long long i=0;i<strlen(s2);i++){
cout<<next[i+1]<<" ";
}
return 0;
}