#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
const int nmax = 6e5 + 5;
const ll oo = 1e18;
const int lg = 17;
const ll base = 1e9 + 7;
const ll mod = 1e9 + 7;
#define pii pair<int, int>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';
using namespace std;
int n, cur = 0;
string s;
ll pw[nmax];
ll rmq[2][nmax][lg + 1];
ll combine(ll a, ll b, int x){
return a * pw[x] + b;
}
void Init(){
pw[0] = 1;
for(int i = 1, j; i <= n; ++i){
pw[i] = pw[i - 1] * base;
rmq[0][i][0] = s[i] - 'a' + 1;
rmq[1][i][0] = s[n - i + 1] - 'a' + 1;
}
for(int j = 1; j <= lg; ++j){
for(int i = 1; i + (1 << j) - 1 <= n; ++i){
for(int t = 0; t < 2; ++t){
rmq[t][i][j] = combine(rmq[t][i][j - 1], rmq[t][i + (1 << (j - 1))][j - 1], 1 << (j - 1));
}
}
}
}
ll get(int l, int r, int t){
int k = r - l + 1;
ll res = 0;
for(int j = 0; j <= __lg(k); ++j){
if(k >> j & 1){
res = combine(res, rmq[t][l][j], 1 << j);
l += 1 << j;
}
}
return res;
}
bool check(int l, int r){
return get(l, r, 0) == get(n - r + 1, n - l + 1, 1);
}
map<ll, bool> mp;
map<ll, ll> par, ind;
int cnt[nmax];
ll f[nmax];
void update(int l, int r){
int u = l, v = r;
bool ok = 1;
while(l <= r){
ll x = get(l, r, 0);
if(!mp[x]){
ind[x] = ++cur;
if(ok){
f[cur]++;
ok = 0;
}
cnt[cur] = r - l + 1;
if(l + 1 <= r - 1){
par[x] = get(l + 1, r - 1, 0);
}
mp[x] = 1;
}
else{
if(ok){
int id = ind[x];
f[id]++;
}
break;
}
++l, --r;
}
}
vector<int> adj[nmax];
void dfs(int u){
for(auto v : adj[u]){
dfs(v);
f[u] += f[v];
}
}
main(){
ios_base::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> s;
n = s.size(); s = ' ' + s + ' ';
Init();
for(int i = 1; i <= n; ++i){
int l = 1, r = min(i, n - i + 1), kq = 1;
while(l <= r){
int mid = r + l >> 1;
if(check(i - mid + 1, i + mid - 1)){
kq = mid;
l = mid + 1;
}
else r = mid - 1;
}
update(i - kq + 1, i + kq - 1);
l = 1, r = min(i, n - i), kq = -1;
while(l <= r){
int mid = r + l >> 1;
if(check(i - mid + 1, i + mid)){
kq = mid;
l = mid + 1;
}
else r = mid - 1;
}
if(kq != -1) update(i - kq + 1, i + kq);
}
for(auto [x, y] : mp){
int v = ind[x];
int u = ind[par[x]];
adj[u].push_back(v);
}
dfs(0);
ll ans = 0;
for(int i = 1; i <= cur; ++i){
ans = max(ans, 1ll * f[i] * cnt[i]);
}
cout << ans;
}
/*
*/
Compilation message
palindrome.cpp: In function 'void Init()':
palindrome.cpp:29:20: warning: unused variable 'j' [-Wunused-variable]
29 | for(int i = 1, j; i <= n; ++i){
| ^
palindrome.cpp: In function 'void update(int, int)':
palindrome.cpp:64:9: warning: unused variable 'u' [-Wunused-variable]
64 | int u = l, v = r;
| ^
palindrome.cpp:64:16: warning: unused variable 'v' [-Wunused-variable]
64 | int u = l, v = r;
| ^
palindrome.cpp: At global scope:
palindrome.cpp:99:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
99 | main(){
| ^~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:110:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
110 | int mid = r + l >> 1;
| ~~^~~
palindrome.cpp:120:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
120 | int mid = r + l >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
23132 KB |
Output is correct |
2 |
Correct |
5 ms |
23140 KB |
Output is correct |
3 |
Correct |
5 ms |
23132 KB |
Output is correct |
4 |
Correct |
6 ms |
23132 KB |
Output is correct |
5 |
Correct |
5 ms |
23384 KB |
Output is correct |
6 |
Correct |
5 ms |
23188 KB |
Output is correct |
7 |
Correct |
5 ms |
23172 KB |
Output is correct |
8 |
Correct |
5 ms |
23132 KB |
Output is correct |
9 |
Correct |
5 ms |
23132 KB |
Output is correct |
10 |
Correct |
5 ms |
23128 KB |
Output is correct |
11 |
Correct |
5 ms |
23132 KB |
Output is correct |
12 |
Correct |
5 ms |
23132 KB |
Output is correct |
13 |
Correct |
5 ms |
23132 KB |
Output is correct |
14 |
Correct |
5 ms |
23132 KB |
Output is correct |
15 |
Correct |
5 ms |
23132 KB |
Output is correct |
16 |
Correct |
5 ms |
23132 KB |
Output is correct |
17 |
Correct |
5 ms |
23192 KB |
Output is correct |
18 |
Correct |
5 ms |
23132 KB |
Output is correct |
19 |
Correct |
5 ms |
23148 KB |
Output is correct |
20 |
Correct |
5 ms |
23132 KB |
Output is correct |
21 |
Correct |
6 ms |
23132 KB |
Output is correct |
22 |
Correct |
6 ms |
23132 KB |
Output is correct |
23 |
Correct |
5 ms |
23148 KB |
Output is correct |
24 |
Correct |
5 ms |
23128 KB |
Output is correct |
25 |
Correct |
6 ms |
23132 KB |
Output is correct |
26 |
Correct |
5 ms |
23132 KB |
Output is correct |
27 |
Correct |
5 ms |
23216 KB |
Output is correct |
28 |
Correct |
6 ms |
23132 KB |
Output is correct |
29 |
Correct |
6 ms |
23132 KB |
Output is correct |
30 |
Correct |
5 ms |
23144 KB |
Output is correct |
31 |
Correct |
5 ms |
23132 KB |
Output is correct |
32 |
Correct |
5 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
23388 KB |
Output is correct |
2 |
Correct |
7 ms |
23388 KB |
Output is correct |
3 |
Correct |
7 ms |
23388 KB |
Output is correct |
4 |
Correct |
6 ms |
23408 KB |
Output is correct |
5 |
Correct |
7 ms |
23388 KB |
Output is correct |
6 |
Correct |
7 ms |
23388 KB |
Output is correct |
7 |
Correct |
7 ms |
23388 KB |
Output is correct |
8 |
Correct |
7 ms |
23388 KB |
Output is correct |
9 |
Correct |
6 ms |
23132 KB |
Output is correct |
10 |
Correct |
6 ms |
23132 KB |
Output is correct |
11 |
Correct |
5 ms |
23148 KB |
Output is correct |
12 |
Correct |
9 ms |
23132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
27480 KB |
Output is correct |
2 |
Correct |
36 ms |
27732 KB |
Output is correct |
3 |
Correct |
39 ms |
27476 KB |
Output is correct |
4 |
Correct |
37 ms |
27476 KB |
Output is correct |
5 |
Correct |
23 ms |
27484 KB |
Output is correct |
6 |
Correct |
25 ms |
27476 KB |
Output is correct |
7 |
Correct |
34 ms |
27384 KB |
Output is correct |
8 |
Correct |
12 ms |
25176 KB |
Output is correct |
9 |
Correct |
12 ms |
25180 KB |
Output is correct |
10 |
Incorrect |
18 ms |
26552 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
534 ms |
79468 KB |
Output is correct |
2 |
Correct |
486 ms |
78660 KB |
Output is correct |
3 |
Correct |
704 ms |
79508 KB |
Output is correct |
4 |
Correct |
563 ms |
78844 KB |
Output is correct |
5 |
Correct |
348 ms |
78912 KB |
Output is correct |
6 |
Correct |
274 ms |
72516 KB |
Output is correct |
7 |
Correct |
384 ms |
74736 KB |
Output is correct |
8 |
Correct |
130 ms |
54264 KB |
Output is correct |
9 |
Correct |
199 ms |
59332 KB |
Output is correct |
10 |
Incorrect |
393 ms |
81604 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
436 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |