#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 |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
768 KB |
Output is correct |
22 |
Correct |
3 ms |
768 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
2 ms |
768 KB |
Output is correct |
28 |
Correct |
3 ms |
640 KB |
Output is correct |
29 |
Correct |
3 ms |
812 KB |
Output is correct |
30 |
Correct |
4 ms |
896 KB |
Output is correct |
31 |
Correct |
3 ms |
896 KB |
Output is correct |
32 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
640 KB |
Output is correct |
2 |
Correct |
44 ms |
28664 KB |
Output is correct |
3 |
Correct |
10 ms |
512 KB |
Output is correct |
4 |
Correct |
64 ms |
47352 KB |
Output is correct |
5 |
Correct |
13 ms |
512 KB |
Output is correct |
6 |
Correct |
10 ms |
512 KB |
Output is correct |
7 |
Correct |
89 ms |
36088 KB |
Output is correct |
8 |
Correct |
10 ms |
640 KB |
Output is correct |
9 |
Correct |
72 ms |
49144 KB |
Output is correct |
10 |
Correct |
70 ms |
52728 KB |
Output is correct |
11 |
Correct |
70 ms |
52728 KB |
Output is correct |
12 |
Correct |
78 ms |
40592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
746 ms |
2736 KB |
Output is correct |
2 |
Runtime error |
398 ms |
132096 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
640 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |