#include <bits/stdc++.h>
using namespace std;
char str[300005];
int n;
int len[300005], ch[300005][26];
int r[300005], f[300005];
char s[101];
int h, t, cnt;
long long sum = 0;
int st, ed;
vector<int> E[300005];
void init() {
for (int i = 0; i < 2; i ++) memset(ch[i], 0, sizeof(ch[i]));
len[0] = 0; len[1] = -1;
f[0] = 1; f[1] = 1;
st = ed = 0;
cnt = 1;
sum = 0;
}
bool valid(int x) {
return 1 <= x && x <= t;
}
void front_ins(int x) {
while (str[x + len[st] + 1] != str[x]) st = f[st];
if (!ch[st][str[x] - 'a']) {
int j = f[st];
while (str[x + len[j] + 1] != str[x]) j = f[j];
len[++ cnt] = len[st] + 2;
int ff = ch[j][str[x] - 'a'];
f[cnt] = ff;
E[ff].push_back(cnt);
ch[st][str[x] - 'a'] = cnt;
memset(ch[cnt], 0, sizeof(ch[cnt]));
}
st = ch[st][str[x] - 'a'];
r[st] ++;
// sum += r[st];
if (len[st] == t - h) ed = st;
}
void back_ins(int x) {
while (str[x - len[ed] - 1] != str[x]) ed = f[ed];
if (!ch[ed][str[x] - 'a']) {
int j = f[ed];
while (str[x - len[j] - 1] != str[x]) j = f[j];
len[++ cnt] = len[ed] + 2;
int ff = ch[j][str[x] - 'a'];
f[cnt] = ff;
E[ff].push_back(cnt);
ch[ed][str[x] - 'a'] = cnt;
memset(ch[cnt], 0, sizeof(ch[cnt]));
}
ed = ch[ed][str[x] - 'a'];
r[ed] ++;
// sum += r[ed];
if (len[ed] == t - h) st = ed;
}
void dfs(int x) {
for (int i = 0; i < (int )E[x].size(); i ++) {
dfs(E[x][i]);
r[x] += r[E[x][i]];
}
}
int main( ) {
init();
scanf("%s", str + 1);
n = (int )strlen(str + 1);
for (int i = 1; i <= n; i ++) {
++ t;
back_ins(i);
}
dfs(0);
for (int i = 2; i <= cnt; i ++) {
sum = max(sum, 1LL * r[i] * len[i]);
}
printf("%lld\n", sum);
return 0;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", str + 1);
~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7424 KB |
Output is correct |
2 |
Correct |
10 ms |
7424 KB |
Output is correct |
3 |
Correct |
9 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7424 KB |
Output is correct |
5 |
Correct |
9 ms |
7424 KB |
Output is correct |
6 |
Correct |
9 ms |
7424 KB |
Output is correct |
7 |
Correct |
8 ms |
7424 KB |
Output is correct |
8 |
Correct |
9 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
8 ms |
7424 KB |
Output is correct |
11 |
Correct |
8 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
9 ms |
7424 KB |
Output is correct |
14 |
Correct |
8 ms |
7424 KB |
Output is correct |
15 |
Correct |
9 ms |
7424 KB |
Output is correct |
16 |
Correct |
8 ms |
7456 KB |
Output is correct |
17 |
Correct |
10 ms |
7424 KB |
Output is correct |
18 |
Correct |
8 ms |
7424 KB |
Output is correct |
19 |
Correct |
10 ms |
7424 KB |
Output is correct |
20 |
Correct |
8 ms |
7424 KB |
Output is correct |
21 |
Correct |
8 ms |
7424 KB |
Output is correct |
22 |
Correct |
8 ms |
7424 KB |
Output is correct |
23 |
Correct |
8 ms |
7424 KB |
Output is correct |
24 |
Correct |
8 ms |
7424 KB |
Output is correct |
25 |
Correct |
10 ms |
7424 KB |
Output is correct |
26 |
Correct |
8 ms |
7424 KB |
Output is correct |
27 |
Correct |
8 ms |
7424 KB |
Output is correct |
28 |
Correct |
10 ms |
7424 KB |
Output is correct |
29 |
Correct |
8 ms |
7424 KB |
Output is correct |
30 |
Correct |
9 ms |
7424 KB |
Output is correct |
31 |
Correct |
8 ms |
7424 KB |
Output is correct |
32 |
Correct |
9 ms |
7424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
7680 KB |
Output is correct |
2 |
Correct |
9 ms |
7552 KB |
Output is correct |
3 |
Correct |
8 ms |
7552 KB |
Output is correct |
4 |
Correct |
9 ms |
7552 KB |
Output is correct |
5 |
Correct |
8 ms |
7552 KB |
Output is correct |
6 |
Correct |
9 ms |
7552 KB |
Output is correct |
7 |
Correct |
9 ms |
7552 KB |
Output is correct |
8 |
Correct |
8 ms |
7552 KB |
Output is correct |
9 |
Correct |
10 ms |
7552 KB |
Output is correct |
10 |
Correct |
9 ms |
7424 KB |
Output is correct |
11 |
Correct |
8 ms |
7424 KB |
Output is correct |
12 |
Correct |
10 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9088 KB |
Output is correct |
2 |
Correct |
10 ms |
9088 KB |
Output is correct |
3 |
Correct |
10 ms |
9344 KB |
Output is correct |
4 |
Correct |
12 ms |
9216 KB |
Output is correct |
5 |
Correct |
9 ms |
8704 KB |
Output is correct |
6 |
Correct |
12 ms |
8832 KB |
Output is correct |
7 |
Correct |
10 ms |
8960 KB |
Output is correct |
8 |
Correct |
8 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
9 ms |
8320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
24448 KB |
Output is correct |
2 |
Correct |
23 ms |
23424 KB |
Output is correct |
3 |
Correct |
29 ms |
26744 KB |
Output is correct |
4 |
Correct |
24 ms |
25088 KB |
Output is correct |
5 |
Correct |
26 ms |
20096 KB |
Output is correct |
6 |
Correct |
23 ms |
17792 KB |
Output is correct |
7 |
Correct |
20 ms |
20224 KB |
Output is correct |
8 |
Correct |
11 ms |
7680 KB |
Output is correct |
9 |
Correct |
18 ms |
12004 KB |
Output is correct |
10 |
Correct |
22 ms |
18304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
58488 KB |
Output is correct |
2 |
Correct |
59 ms |
53408 KB |
Output is correct |
3 |
Correct |
61 ms |
65400 KB |
Output is correct |
4 |
Correct |
52 ms |
56576 KB |
Output is correct |
5 |
Correct |
92 ms |
46456 KB |
Output is correct |
6 |
Correct |
48 ms |
48376 KB |
Output is correct |
7 |
Correct |
48 ms |
44792 KB |
Output is correct |
8 |
Correct |
15 ms |
8192 KB |
Output is correct |
9 |
Correct |
15 ms |
8192 KB |
Output is correct |
10 |
Correct |
63 ms |
39416 KB |
Output is correct |
11 |
Correct |
61 ms |
53752 KB |
Output is correct |
12 |
Correct |
20 ms |
13312 KB |
Output is correct |