#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct eertree{
vector<vector<int>> t;
int n, last, sz;
vector<int> s, len, link, qt;
eertree(int N){
t = vector(N + 2, vector(26, int()));
s = len = link = qt = vector<int>(N + 2);
s[0] = -1;
link[0] = 1, len[0] = 0, link[1] = 1, len[1] = -1;
sz = 2, last = 0, n = 1;
}
void add(char c){
s[n++] = c -= 'a';
while(s[n - len[last] - 2] != c) last = link[last];
if(!t[last][c]){
int prev = link[last];
while(s[n - len[prev] - 2] != c) prev = link[prev];
link[sz] = t[prev][c];
len[sz] = len[last] + 2;
t[last][c] = sz ++;
}
qt[last = t[last][c]] ++;
}
int size(){return sz - 2;}
ll propagate(){
ll ret = 0;
for (int i = n; i > 1; i--)
{
qt[link[i]] += qt[i];
ret += qt[i];
}
return ret;
}
};
int main(){
string s;
cin >> s;
struct eertree ee(s.size());
for (char c: s)
{
ee.add(c);
}
ee.propagate();
ll ans = 0;
for (int i = 0; i <= s.size() + 1; i++)
{
ll len = ee.len[i];
ll q = ee.qt[i];
ans = max(ans, len * q);
}
cout << ans << endl;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int i = 0; i <= s.size() + 1; i++)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
432 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
352 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
436 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1888 KB |
Output is correct |
4 |
Correct |
1 ms |
1884 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
1 ms |
1884 KB |
Output is correct |
7 |
Correct |
2 ms |
1884 KB |
Output is correct |
8 |
Correct |
2 ms |
1884 KB |
Output is correct |
9 |
Correct |
1 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
1756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
15452 KB |
Output is correct |
2 |
Correct |
12 ms |
15452 KB |
Output is correct |
3 |
Correct |
11 ms |
15452 KB |
Output is correct |
4 |
Correct |
14 ms |
15452 KB |
Output is correct |
5 |
Correct |
12 ms |
15448 KB |
Output is correct |
6 |
Correct |
12 ms |
15484 KB |
Output is correct |
7 |
Correct |
15 ms |
15452 KB |
Output is correct |
8 |
Correct |
11 ms |
15520 KB |
Output is correct |
9 |
Correct |
11 ms |
15452 KB |
Output is correct |
10 |
Correct |
11 ms |
15392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
45548 KB |
Output is correct |
2 |
Correct |
37 ms |
45560 KB |
Output is correct |
3 |
Correct |
33 ms |
45552 KB |
Output is correct |
4 |
Correct |
33 ms |
45560 KB |
Output is correct |
5 |
Correct |
32 ms |
45524 KB |
Output is correct |
6 |
Correct |
35 ms |
45636 KB |
Output is correct |
7 |
Correct |
39 ms |
45560 KB |
Output is correct |
8 |
Correct |
34 ms |
45556 KB |
Output is correct |
9 |
Correct |
32 ms |
45552 KB |
Output is correct |
10 |
Correct |
30 ms |
45560 KB |
Output is correct |
11 |
Correct |
34 ms |
45560 KB |
Output is correct |
12 |
Correct |
39 ms |
45560 KB |
Output is correct |