#include <cstdio>
#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;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:27:2: error: 'memset' was not declared in this scope
memset(c, -1, sizeof c);
^~~~~~
palindrome.cpp:33:17: warning: array subscript has type 'char' [-Wchar-subscripts]
if(!~c[p][s[i]])
^
palindrome.cpp:35:13: warning: array subscript has type 'char' [-Wchar-subscripts]
c[p][s[i]]=++X;
^
palindrome.cpp:40:22: warning: array subscript has type 'char' [-Wchar-subscripts]
l[p]=c[l[p]][s[i]];
^
palindrome.cpp:43:4: error: 'assert' was not declared in this scope
assert(~l[p]);
^~~~~~
palindrome.cpp:43:4: note: suggested alternative: 'short'
assert(~l[p]);
^~~~~~
short
palindrome.cpp:47:15: warning: array subscript has type 'char' [-Wchar-subscripts]
p=c[p][s[i]];
^
palindrome.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", s+1);
~~~~~^~~~~~~~~~~~