0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-24 00:08:47 +00:00
OI-codes/S2OJ/166/data/std.cpp

37 lines
704 B (Stored with Git LFS)
C++

#include <bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1,c=getchar();
while(c<48) c=='-'&&(f=-1),c=getchar();
while(c>47) x=x*10+c-'0',c=getchar();
return x*f;
}
const int MAXN = 25000005;
char s[MAXN],t[MAXN];
int f[MAXN],n,ans;
inline void manacher()
{
for(int i=1,mr=1,mid=0; i<=n; ++i)
{
f[i]=i<mr?min(f[mid+mid-i],mr-i):1;
while(s[i+f[i]]==s[i-f[i]]) ++f[i];
if(i+f[i]>mr) mr=i+f[i],mid=i;
}
}
int main(int argc, char const *argv[])
{
scanf("%s",t+1); n=strlen(t+1);
s[0]='/'; s[1]='#';
for(int i=1; i<=n; ++i)
s[i<<1]=t[i],s[i<<1|1]='#';
n=n<<1|1; s[n+1]='\\'; manacher();
for(int i=1; i<=n; ++i) ans=max(ans,f[i]);
printf("%d\n", ans-1);
return 0;
}