听说用字符串过不了,用字符数组才能过,为什么?
#include<bits/stdc++.h>
#define int long long
using namespace std;
int ans=0,p[25000005];
signed main(){
int t;
cin>>t;
while(t--){
string s;
s+='^';
s+='|';
char cc;
cin>>cc;
s+=cc;
while(cc=getchar()){
if(cc>='a'&&cc<='z'){
s+='|';
s+=cc;
}
else{
break;
}
}
s+='|';
s+='&';
int ans=1,r=0,c=0;
for(int i=1;s[i+1]!='\0';i++){
if(i<=r) p[i]=min(p[c*2-i],r-i);
while(s[i+p[i]+1]==s[i-p[i]-1]) p[i]++;
if(i+p[i]>r){
r=i+p[i];
c=i;
}
}
for(int i=1;s[i+1]!='\0';i++){
ans=max(ans,p[i]);
}
cout<<ans<<"\n";
}
return 0;
}