This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 2;
int n, bor[26][N], cnt[N * 27], cn = 1;
long long ans;
string s;
void add(int id, int c){
int v = 1;
for(int len = 0; len < min(n - id + 1, id); len ++){
if(id - len <= 0 || id + len + c > n || s[id - len] != s[id + len + c]){
break;
}
int now = s[id - len] - 'a';
if(!bor[now][v]){
bor[now][v] = ++ cn;
}
v = bor[now][v];
}
cnt[v] ++;
}
void f(int v, int len, int c){
for(int i = 0; i < 26; i ++){
if(bor[i][v]){
f(bor[i][v], len + 1, c);
cnt[v] += cnt[ bor[i][v] ];
}
}
ans = max(ans, (len * 2 - c - 2) *1ll* cnt[v]);
}
int main(){
cin >> s;
n = s.size();
s = ' ' + s;
for(int i = 1; i <= n; i ++){
add(i, 0);
}
f(1, 1, 1);
cn = 1;
memset(bor, 0, sizeof(bor));
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i < n; i ++){
if(s[i] == s[i + 1])
add(i, 1);
}
f(1, 1, 0);
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |