#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 3e5 + 500;
const int INF = 0x3f3f3f3f;
struct node{
node* CH[30];
node* bk;
int len, cnt;
} *n0, *n1;
bool cmp(node* X, node* Y){
return X -> len > Y -> len;
}
char s[N];
int n;
ll mx;
vector < node* > v;
void precompute(){
n1 = new node(); n0 = new node();
n1 -> len = -1, n0 -> len = 0;
n0 -> bk = n1; n1 -> bk = n1;
node* cur = n0;
for(int i = 0;i < n;i++){
for(; cur->len + 1 > i || s[i - cur->len - 1] != s[i]; cur = cur -> bk);
node *rmb = cur -> bk;
if(cur -> CH[s[i] - 'a'] == NULL)
cur -> CH[s[i] - 'a'] = new node(), v.PB(cur -> CH[s[i] - 'a']);
cur -> CH[s[i] - 'a'] -> len = cur -> len + 2;
cur = cur -> CH[s[i] - 'a'];
cur -> cnt++;
//printf("len = %d\n", cur -> len);
for(; rmb -> len + 1 > i || s[i - rmb->len - 1] != s[i]; rmb = rmb -> bk);
if(cur -> len == 1)
cur -> bk = n0;
else{
if(rmb -> CH[s[i] - 'a'] == NULL)
rmb -> CH[s[i] - 'a'] = new node(), v.PB(rmb -> CH[s[i] - 'a']);
cur -> bk = rmb -> CH[s[i] - 'a'];
}
//printf("bk = %d\n", cur -> bk -> len);
}
}
int main(){
scanf("%s", s);
n = strlen(s);
precompute();
sort(v.begin(), v.end(), cmp);
for(int i = 0;i < v.size();i++){
mx = max(mx, (ll)v[i] -> len * v[i] -> cnt);
v[i] -> bk -> cnt += v[i] -> cnt;
}
printf("%lld\n", mx);
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:63:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0;i < v.size();i++){
| ~~^~~~~~~~~~
palindrome.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%s", s);
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
500 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
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 |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 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 |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3164 KB |
Output is correct |
2 |
Correct |
3 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
2 ms |
3160 KB |
Output is correct |
5 |
Correct |
2 ms |
2996 KB |
Output is correct |
6 |
Correct |
2 ms |
3160 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
27856 KB |
Output is correct |
2 |
Correct |
25 ms |
27856 KB |
Output is correct |
3 |
Correct |
18 ms |
28036 KB |
Output is correct |
4 |
Correct |
26 ms |
27856 KB |
Output is correct |
5 |
Correct |
27 ms |
27856 KB |
Output is correct |
6 |
Correct |
17 ms |
20432 KB |
Output is correct |
7 |
Correct |
19 ms |
23760 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
6872 KB |
Output is correct |
10 |
Correct |
20 ms |
23700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
83648 KB |
Output is correct |
2 |
Correct |
75 ms |
83456 KB |
Output is correct |
3 |
Correct |
67 ms |
84692 KB |
Output is correct |
4 |
Correct |
85 ms |
84264 KB |
Output is correct |
5 |
Correct |
90 ms |
83196 KB |
Output is correct |
6 |
Correct |
68 ms |
76344 KB |
Output is correct |
7 |
Correct |
63 ms |
69308 KB |
Output is correct |
8 |
Correct |
4 ms |
1372 KB |
Output is correct |
9 |
Correct |
4 ms |
1428 KB |
Output is correct |
10 |
Correct |
67 ms |
68236 KB |
Output is correct |
11 |
Correct |
67 ms |
83896 KB |
Output is correct |
12 |
Correct |
8 ms |
8660 KB |
Output is correct |