#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#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], *bk;
int len, cnt;
};
bool cmp(node* X, node* Y){
return X->len > Y->len;
}
string s;
int n;
ll mx;
vector < node* > v;
void precompute(){
node *n1 = new node();
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++;
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'];
}
}
}
int main(){
cin >> s;
n = (int)s.size();
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;
}
cout << mx << endl;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i = 0;i < v.size();i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 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 |
0 ms |
348 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 |
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 |
348 KB |
Output is correct |
30 |
Correct |
1 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 |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
612 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
2980 KB |
Output is correct |
4 |
Correct |
2 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3124 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
27732 KB |
Output is correct |
2 |
Correct |
25 ms |
27732 KB |
Output is correct |
3 |
Correct |
18 ms |
27848 KB |
Output is correct |
4 |
Correct |
27 ms |
27732 KB |
Output is correct |
5 |
Correct |
31 ms |
27980 KB |
Output is correct |
6 |
Correct |
18 ms |
20304 KB |
Output is correct |
7 |
Correct |
19 ms |
23832 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
6 ms |
6788 KB |
Output is correct |
10 |
Correct |
22 ms |
23524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
84612 KB |
Output is correct |
2 |
Correct |
78 ms |
84184 KB |
Output is correct |
3 |
Correct |
64 ms |
83844 KB |
Output is correct |
4 |
Correct |
82 ms |
83420 KB |
Output is correct |
5 |
Correct |
93 ms |
83932 KB |
Output is correct |
6 |
Correct |
75 ms |
74936 KB |
Output is correct |
7 |
Correct |
74 ms |
69048 KB |
Output is correct |
8 |
Correct |
6 ms |
1012 KB |
Output is correct |
9 |
Correct |
6 ms |
1016 KB |
Output is correct |
10 |
Correct |
70 ms |
67964 KB |
Output is correct |
11 |
Correct |
67 ms |
83680 KB |
Output is correct |
12 |
Correct |
12 ms |
8440 KB |
Output is correct |