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;
using ll = long long;
using ld = long double;
ll res = 0;
const int C = 1000000;
struct PTree{
struct Node{
int len, cnt, slink, dpt, to[26];
} tree[C];
int suf = 0;
int idxx = 0;
string s = "";
void init(){
tree[1].len = -1, tree[1].cnt = 0, tree[1].slink = 1, tree[1].dpt = 0;
tree[2].len = 0, tree[2].cnt = 0, tree[2].slink = 1, tree[1].dpt = 0;
suf = idxx = 2;
}
void addChar(char c){
s += c;
int n = s.size();
while(n - 2 - tree[suf].len < 0 || s[n - 2 - tree[suf].len] != c) suf = tree[suf].slink;
int node = tree[suf].to[c - 'a'];
if(node == 0){
node = ++idxx;
tree[suf].to[c - 'a'] = idxx;
tree[node].len = tree[suf].len + 2;
if(suf == 1) tree[node].slink = 2;
else{
int v = tree[suf].slink;
while(s[n - 2 - tree[v].len] != c) v = tree[v].slink;
tree[node].slink = tree[v].to[c - 'a'];
}
tree[node].dpt = tree[tree[node].slink].dpt + 1;
}
tree[node].cnt++;
suf = node;
}
void calc(){
for(int node=idxx; node>=3; node--){
res = max(res, 1LL*tree[node].len*tree[node].cnt);
tree[tree[node].slink].cnt += tree[node].cnt;
}
}
} pal;
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
string s;
cin >> s;
pal.init();
for(auto c : s) pal.addChar(c);
pal.calc();
cout << res << "\n";
return 0;
}
# | 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... |