이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int t[N * 100][26];
int b[N * 100];
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][a[r] - 'a'] == 0)
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... |