# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
253085 | frodakcin | Palindromes (APIO14_palindrome) | C++11 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <vector>
template<typename T> bool ckmax(T& a, const T& b) {return a<b?a=b,1:0;}
const int MN = 3e5+10;
const int MK = 26;
typedef long long ll;
int N, c[MN][MK], l[MN], d[MN], p, X=1, v[MN];
ll f;
std::vector<int> dw[MN];
char s[MN];
void dfs(int n)
{
s[n]=1;
for(auto x:dw[n])
dfs(x), s[n]+=s[x];
ckmax(f, (ll)s[n]*d[n]);
}
int main()
{
scanf(" %s", s+1);
for(N=1;s[N];++N)s[N]-='a';
s[0]=-1, s[N--]=-2;
memset(c, -1, sizeof c);
d[0]=l[0]=-1, d[1]=l[1]=0;
dw[0].push_back(1);
for(int i=1;i<=N;++i)
{
for(;s[i]!=s[i-d[p]-1];)p=l[p];
if(!~c[p][s[i]])
{
c[p][s[i]]=++X;
d[X]=d[p]+2, l[X]=l[p];
p=X;
for(;~l[p] && s[i]!=s[i-d[l[p]]-1];l[p]=l[l[p]]);
if(~l[p] && s[i]==s[i-d[l[p]]-1])
l[p]=c[l[p]][s[i]];
else
l[p]=1;
assert(~l[p]);
dw[l[p]].push_back(p);
}
else
p=c[p][s[i]];
++v[p];
}
dfs(0);
printf("%lld\n", f);
return 0;
}