#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
char s[N]; // 1-indexed
int T, idx, Tree[N][26], link[N], len[N], occ[N] , num[N], n;
inline void extend(int p) {
while (s[p - len[T] - 1] != s[p]) T = link[T];
int x = link[T], c = s[p] - 'a';
while (s[p - len[x] - 1] != s[p]) x = link[x];
if (!Tree[T][c]) {
Tree[T][c] = ++idx;
len[idx] = len[T] + 2;
link[idx] = len[idx] == 1 ? 2 : Tree[x][c];
num[idx] = 1 + num[link[idx]];
} T = Tree[T][c],++occ[T];
}
long long build() {
long long tot_pal=0;
memset(Tree, 0, sizeof Tree);
memset(occ, 0, sizeof occ);
len[1] = -1, len[2] = 0;
link[1] = link[2] = 1;
T = idx = 2;
for (int i = 1; i <= n; i++) {
extend(i);
tot_pal+=num[T];
// cout<<"# "<<num[T]<<endl;
}
for (int i = idx; i > 2; i--) {
occ[link[i]] += occ[i];
}
// for(int i=3;i<=idx;i++)cout<<len[i]<<' '<<occ[i]<<endl;
return tot_pal;
}
int main(int argc, char const *argv[])
{
scanf("%s", s + 1);
n = strlen(s + 1);
build();
long long ma=0;
for(int i=3;i<=idx;i++)ma=max(ma,(long long)len[i]*(long long)occ[i]);
printf("%lld\n", ma);
return 0;
}
Compilation message
palindrome.cpp: In function 'int main(int, const char**)':
palindrome.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s + 1);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
10872 KB |
Output is correct |
2 |
Correct |
9 ms |
10872 KB |
Output is correct |
3 |
Correct |
10 ms |
10872 KB |
Output is correct |
4 |
Correct |
10 ms |
10872 KB |
Output is correct |
5 |
Correct |
10 ms |
10872 KB |
Output is correct |
6 |
Correct |
9 ms |
10872 KB |
Output is correct |
7 |
Correct |
10 ms |
10872 KB |
Output is correct |
8 |
Correct |
10 ms |
10872 KB |
Output is correct |
9 |
Correct |
9 ms |
10872 KB |
Output is correct |
10 |
Correct |
10 ms |
10872 KB |
Output is correct |
11 |
Correct |
10 ms |
10872 KB |
Output is correct |
12 |
Correct |
10 ms |
10872 KB |
Output is correct |
13 |
Correct |
10 ms |
10876 KB |
Output is correct |
14 |
Correct |
10 ms |
10876 KB |
Output is correct |
15 |
Correct |
10 ms |
10872 KB |
Output is correct |
16 |
Correct |
10 ms |
10872 KB |
Output is correct |
17 |
Correct |
10 ms |
10872 KB |
Output is correct |
18 |
Correct |
10 ms |
10872 KB |
Output is correct |
19 |
Correct |
10 ms |
10876 KB |
Output is correct |
20 |
Correct |
10 ms |
10872 KB |
Output is correct |
21 |
Correct |
11 ms |
10872 KB |
Output is correct |
22 |
Correct |
10 ms |
10872 KB |
Output is correct |
23 |
Correct |
10 ms |
10872 KB |
Output is correct |
24 |
Correct |
10 ms |
10872 KB |
Output is correct |
25 |
Correct |
10 ms |
10872 KB |
Output is correct |
26 |
Correct |
10 ms |
10872 KB |
Output is correct |
27 |
Correct |
10 ms |
10872 KB |
Output is correct |
28 |
Correct |
9 ms |
10872 KB |
Output is correct |
29 |
Correct |
10 ms |
10872 KB |
Output is correct |
30 |
Correct |
10 ms |
10872 KB |
Output is correct |
31 |
Correct |
10 ms |
10872 KB |
Output is correct |
32 |
Correct |
10 ms |
10872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
10872 KB |
Output is correct |
2 |
Correct |
9 ms |
10872 KB |
Output is correct |
3 |
Correct |
10 ms |
10872 KB |
Output is correct |
4 |
Correct |
10 ms |
10872 KB |
Output is correct |
5 |
Correct |
10 ms |
10872 KB |
Output is correct |
6 |
Correct |
10 ms |
10872 KB |
Output is correct |
7 |
Correct |
10 ms |
10872 KB |
Output is correct |
8 |
Correct |
10 ms |
10872 KB |
Output is correct |
9 |
Correct |
10 ms |
10872 KB |
Output is correct |
10 |
Correct |
10 ms |
10872 KB |
Output is correct |
11 |
Correct |
10 ms |
10872 KB |
Output is correct |
12 |
Correct |
10 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
11000 KB |
Output is correct |
2 |
Correct |
10 ms |
11000 KB |
Output is correct |
3 |
Correct |
10 ms |
11000 KB |
Output is correct |
4 |
Correct |
10 ms |
11000 KB |
Output is correct |
5 |
Correct |
10 ms |
11000 KB |
Output is correct |
6 |
Correct |
10 ms |
11000 KB |
Output is correct |
7 |
Correct |
10 ms |
11000 KB |
Output is correct |
8 |
Correct |
10 ms |
10872 KB |
Output is correct |
9 |
Correct |
10 ms |
10872 KB |
Output is correct |
10 |
Correct |
10 ms |
11004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12152 KB |
Output is correct |
2 |
Correct |
14 ms |
12152 KB |
Output is correct |
3 |
Correct |
14 ms |
12152 KB |
Output is correct |
4 |
Correct |
13 ms |
12152 KB |
Output is correct |
5 |
Correct |
12 ms |
12152 KB |
Output is correct |
6 |
Correct |
12 ms |
11896 KB |
Output is correct |
7 |
Correct |
12 ms |
12024 KB |
Output is correct |
8 |
Correct |
11 ms |
11004 KB |
Output is correct |
9 |
Correct |
12 ms |
11260 KB |
Output is correct |
10 |
Correct |
12 ms |
12024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |