ZZ_WYZ @ 2024-10-16 21:11:53
#include<bits/stdc++.h>
using namespace std;
int d1[514514],d2[514514];
string s;
int n;
int main(){
cin>>n;
cin>>s;
for(int i=0,l=0,r=-1;i<n;i++){
int k;
if(i>r){
k=0;
}
else{
k=min(d2[l+r-i+1],r-i+1);
}
while(i-k-1>=0&&i+k<n&&i+k<n&&s[i-k-1]==s[i+k]){
k++;
}
d2[i]=k;
k--;
if(i+k>r){
l=i-k-1;
r=i+k;
}
}int cnt=0;
int ans=0;
for(int i=0;i<n;i++){
if(d2[i]!=0&&d2[i]%2==0){
if(i-d2[i]/2>=0)
if(d2[i-d2[i]/2]==d2[i]/2){
ans=max(ans,d2[i]*2);
}
}
}
cout<<ans;
return 0;
}
by yzjznbQWQ @ 2024-10-17 17:00:29
+1