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;
const int N = 10004;
const long long P = 31;
int n;
char aa[N], a[N];
long long ast[N];
long long p[N], s[N];
bool pal(int l, int r)
{
return (p[r] - p[l - 1]) * ast[n - r] == (s[l] - s[r + 1]) * ast[l - 1];
}
int z;
map<int, int> t[N * 200];
int b[N * 200];
int main()
{
cin >> aa;
n = strlen(aa);
for (int i = 1; i <= n; ++i)
a[i] = aa[i - 1];
ast[0] = 1;
for (int i = 1; i <= n; ++i)
ast[i] = ast[i - 1] * P;
for (int i = 1; i <= n; ++i)
p[i] = p[i - 1] + ast[i - 1] * (a[i] - 'a' + 1);
for (int i = n; i >= 1; --i)
s[i] = s[i + 1] + ast[n - i] * (a[i] - 'a' + 1);
for (int l = 1; l <= n; ++l)
{
int pos = 0;
for (int r = l; r <= n; ++r)
{
if (t[pos].find(a[r] - 'a') == t[pos].end())
t[pos][a[r] - 'a'] = ++z;
pos = t[pos][a[r] - 'a'];
b[pos]++;
}
}
int ans = 0;
for (int l = 1; l <= n; ++l)
{
int pos = 0;
for (int r = l; r <= n; ++r)
{
pos = t[pos][a[r] - 'a'];
if (pal(l, r))
ans = max(ans, b[pos] * (r - l + 1));
}
}
cout << ans << endl;
return 0;
}
# | 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... |