#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define N 300005
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
ll mx = 1;
struct Node{
Node *c[26], *p[19];
int sz = 0, de;
int trav(){
for(int i = 0; i < 26; ++i){
if(!c[i])
continue;
sz += c[i] -> trav();
delete(c[i]);
c[i] = NULL;
}
mx = max(mx, 1LL * de * sz);
return sz;
}
Node* go(int a){
if(c[a])
return c[a];
c[a] = new Node();
c[a] -> de = de + 2;
c[a] -> p[0] = this;
for(int i = 1; ; ++i){
c[a] -> p[i] = c[a] -> p[i - 1] -> p[i - 1];
if(!c[a] -> p[i]) break;
}
return c[a];
}
} *r1 = new Node();
int d1[N];
Node *w1[N];
int a[N];
int lg[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin>>s;
for(int i = 2; i < N; i <<= 1)
lg[i] = lg[i >> 1] + 1;
r1 -> de = -1;
int n = s.size();
for(int i = 0; i < n; ++i)
a[i] = s[i] - 'a';
int lo = -1, r = -1;
for(int i = 0; i < n; ++i){
if(r < i){
d1[i] = 1;
w1[i] = r1 -> go(a[i]);
} else {
w1[i] = w1[lo - (i - lo)];
d1[i] = d1[lo - (i - lo)];
int w = max(0, d1[i] - (r - i));
d1[i] -= w;
while(w){
w1[i] = w1[i] -> p[lg[w & -w]];
w -= w & -w;
}
}
while(i + d1[i] < n && i - d1[i] >= 0 && a[i - d1[i]] == a[i + d1[i]]){
w1[i] = w1[i] -> go(a[i + d1[i]]);
++d1[i];
}
++w1[i] -> sz;
if(r <= i + d1[i] - 1){
r = i + d1[i] - 1;
lo = i;
}
}
r1 -> trav();
r1 -> de = 0;
lo = -1, r = -1;
for(int i = 0; i < n; ++i){
if(r < i){
d1[i] = 0;
w1[i] = r1;
} else {
w1[i] = w1[lo - (i - lo)];
d1[i] = d1[lo - (i - lo)];
int w = max(0, d1[i] - (r - i));
d1[i] -= w;
while(w){
w1[i] = w1[i] -> p[lg[w & -w]];
w -= w & -w;
}
}
while(i + d1[i] < n && i - d1[i] - 1 >= 0 && a[i - d1[i] - 1] == a[i + d1[i]]){
w1[i] = w1[i] -> go(a[i + d1[i]]);
++d1[i];
}
++w1[i] -> sz;
if(r <= i + d1[i] - 1){
r = i + d1[i] - 1;
lo = i;
}
}
r1 -> trav();
cout<<mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
768 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
768 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
4480 KB |
Output is correct |
2 |
Correct |
10 ms |
4352 KB |
Output is correct |
3 |
Correct |
12 ms |
2612 KB |
Output is correct |
4 |
Correct |
9 ms |
2612 KB |
Output is correct |
5 |
Correct |
9 ms |
4352 KB |
Output is correct |
6 |
Correct |
9 ms |
4096 KB |
Output is correct |
7 |
Correct |
9 ms |
4352 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
8 ms |
3200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
40952 KB |
Output is correct |
2 |
Correct |
89 ms |
40184 KB |
Output is correct |
3 |
Correct |
71 ms |
22172 KB |
Output is correct |
4 |
Correct |
63 ms |
21676 KB |
Output is correct |
5 |
Correct |
55 ms |
40568 KB |
Output is correct |
6 |
Correct |
46 ms |
29824 KB |
Output is correct |
7 |
Correct |
45 ms |
25856 KB |
Output is correct |
8 |
Correct |
7 ms |
2432 KB |
Output is correct |
9 |
Correct |
18 ms |
6912 KB |
Output is correct |
10 |
Correct |
55 ms |
34556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
272 ms |
122496 KB |
Output is correct |
2 |
Correct |
218 ms |
119424 KB |
Output is correct |
3 |
Correct |
186 ms |
65924 KB |
Output is correct |
4 |
Correct |
146 ms |
63592 KB |
Output is correct |
5 |
Correct |
162 ms |
121804 KB |
Output is correct |
6 |
Correct |
150 ms |
91132 KB |
Output is correct |
7 |
Correct |
124 ms |
76544 KB |
Output is correct |
8 |
Correct |
12 ms |
6152 KB |
Output is correct |
9 |
Correct |
11 ms |
6152 KB |
Output is correct |
10 |
Correct |
150 ms |
101452 KB |
Output is correct |
11 |
Correct |
251 ms |
122356 KB |
Output is correct |
12 |
Correct |
23 ms |
11528 KB |
Output is correct |