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;
typedef long long ll;
const int N = 3e5+111;
int n;
string s;
ll res;
vector<int> Adj[N];
struct node{
int next[26];
int sufflink;
int len;
int num;
node(){
memset(next,255,sizeof(next));
}
} Tree[N];
int num, suff;
void init(){
num = suff = 2;
Tree[1].len = -1; Tree[1].sufflink = 1;
Tree[2].len = 0; Tree[2].sufflink = 1;
}
void add(int p){
int x = s[p]-'a';
int cur = suff, curLen;
while(1){
curLen = Tree[cur].len;
if(p-curLen-1>=0&&s[p-curLen-1]==s[p]) break;
cur = Tree[cur].sufflink;
}
if(Tree[cur].next[x]!=-1){
suff = Tree[cur].next[x];
Tree[suff].num++;
return;
}
suff = ++num;
Tree[cur].next[x] = num;
Tree[num].len = Tree[cur].len+2;
Tree[num].num++;
if(Tree[num].len==1){
Tree[num].sufflink = 2;
Adj[2].push_back(num);
return;
}
while(1){
cur = Tree[cur].sufflink;
curLen = Tree[cur].len;
if(p-curLen-1>=0&&s[p-curLen-1]==s[p]){
Tree[num].sufflink = Tree[cur].next[x];
Adj[Tree[cur].next[x]].push_back(num);
return;
}
}
}
void DFS(int u){
for(auto v: Adj[u]){
DFS(v);
Tree[u].num += Tree[v].num;
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>s;
n = s.size();
init();
for(int i = 0; i < n; i++){
add(i);
}
DFS(2);
for(int i = 3; i <= num; i++){
res = max(res,(ll)Tree[i].num*Tree[i].len);
}
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... |