# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
625149 | Hanksburger | Palindromes (APIO14_palindrome) | C++17 | 24 ms | 35108 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 <bits/stdc++.h>
using namespace std;
int nxt[300005][26], suff[300005], len[300005], freq[300005], cur=1, cnt=2;
string s;
void add(int x)
{
while (s[x-len[cur]-1]!=s[x])
cur=suff[cur];
int y=s[x]-'a';
if (nxt[cur][y])
{
cur=nxt[cur][y];
freq[cur]++;
return;
}
nxt[cur][y]=++cnt;
len[cnt]=len[cur]+2;
freq[cnt]++;
if (len[cnt]==1)
{
suff[cnt]=2;
cur=cnt;
return;
}
do cur=suff[cur];
while (s[x-len[cur]-1]!=s[x]);
suff[cnt]=nxt[cur][y];
cur=cnt;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
len[1]=-1;
suff[1]=suff[2]=1;
cin >> s;
for (int i=0; i<s.length(); i++)
add(i);
long long ans=0;
for (int i=cnt; i>=3; i--)
{
ans=max(ans, 1LL*freq[i]*len[i]);
freq[suff[i]]+=freq[i];
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |