#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 |
1 |
Correct |
6 ms |
43204 KB |
Output is correct |
2 |
Correct |
6 ms |
43204 KB |
Output is correct |
3 |
Correct |
3 ms |
43204 KB |
Output is correct |
4 |
Correct |
3 ms |
43204 KB |
Output is correct |
5 |
Correct |
3 ms |
43204 KB |
Output is correct |
6 |
Correct |
0 ms |
43204 KB |
Output is correct |
7 |
Correct |
13 ms |
43204 KB |
Output is correct |
8 |
Correct |
6 ms |
43204 KB |
Output is correct |
9 |
Correct |
3 ms |
43204 KB |
Output is correct |
10 |
Correct |
6 ms |
43204 KB |
Output is correct |
11 |
Correct |
6 ms |
43204 KB |
Output is correct |
12 |
Correct |
6 ms |
43204 KB |
Output is correct |
13 |
Correct |
3 ms |
43204 KB |
Output is correct |
14 |
Correct |
3 ms |
43204 KB |
Output is correct |
15 |
Correct |
3 ms |
43204 KB |
Output is correct |
16 |
Correct |
6 ms |
43204 KB |
Output is correct |
17 |
Correct |
0 ms |
43204 KB |
Output is correct |
18 |
Correct |
6 ms |
43204 KB |
Output is correct |
19 |
Correct |
9 ms |
43204 KB |
Output is correct |
20 |
Correct |
0 ms |
43204 KB |
Output is correct |
21 |
Correct |
3 ms |
43204 KB |
Output is correct |
22 |
Correct |
0 ms |
43204 KB |
Output is correct |
23 |
Correct |
3 ms |
43204 KB |
Output is correct |
24 |
Correct |
6 ms |
43204 KB |
Output is correct |
25 |
Correct |
6 ms |
43204 KB |
Output is correct |
26 |
Correct |
6 ms |
43204 KB |
Output is correct |
27 |
Correct |
6 ms |
43204 KB |
Output is correct |
28 |
Correct |
9 ms |
43204 KB |
Output is correct |
29 |
Correct |
3 ms |
43204 KB |
Output is correct |
30 |
Correct |
3 ms |
43204 KB |
Output is correct |
31 |
Correct |
9 ms |
43204 KB |
Output is correct |
32 |
Correct |
16 ms |
43204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
43204 KB |
Output is correct |
2 |
Correct |
3 ms |
43204 KB |
Output is correct |
3 |
Correct |
3 ms |
43204 KB |
Output is correct |
4 |
Correct |
3 ms |
43204 KB |
Output is correct |
5 |
Correct |
3 ms |
43204 KB |
Output is correct |
6 |
Correct |
3 ms |
43204 KB |
Output is correct |
7 |
Correct |
13 ms |
43204 KB |
Output is correct |
8 |
Correct |
9 ms |
43204 KB |
Output is correct |
9 |
Correct |
6 ms |
43204 KB |
Output is correct |
10 |
Correct |
3 ms |
43204 KB |
Output is correct |
11 |
Correct |
13 ms |
43204 KB |
Output is correct |
12 |
Correct |
13 ms |
43204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
43576 KB |
Output is correct |
2 |
Correct |
9 ms |
43512 KB |
Output is correct |
3 |
Correct |
6 ms |
43812 KB |
Output is correct |
4 |
Correct |
9 ms |
43740 KB |
Output is correct |
5 |
Correct |
6 ms |
43336 KB |
Output is correct |
6 |
Correct |
9 ms |
43336 KB |
Output is correct |
7 |
Correct |
6 ms |
43468 KB |
Output is correct |
8 |
Correct |
6 ms |
43204 KB |
Output is correct |
9 |
Correct |
6 ms |
43204 KB |
Output is correct |
10 |
Correct |
3 ms |
43204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
48612 KB |
Output is correct |
2 |
Correct |
13 ms |
47588 KB |
Output is correct |
3 |
Correct |
13 ms |
50952 KB |
Output is correct |
4 |
Correct |
16 ms |
49260 KB |
Output is correct |
5 |
Correct |
19 ms |
44412 KB |
Output is correct |
6 |
Correct |
13 ms |
45136 KB |
Output is correct |
7 |
Correct |
9 ms |
46196 KB |
Output is correct |
8 |
Correct |
6 ms |
43356 KB |
Output is correct |
9 |
Correct |
9 ms |
44940 KB |
Output is correct |
10 |
Correct |
13 ms |
44280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
60028 KB |
Output is correct |
2 |
Correct |
59 ms |
54976 KB |
Output is correct |
3 |
Correct |
29 ms |
67056 KB |
Output is correct |
4 |
Correct |
56 ms |
58092 KB |
Output is correct |
5 |
Correct |
83 ms |
48104 KB |
Output is correct |
6 |
Correct |
39 ms |
53752 KB |
Output is correct |
7 |
Correct |
39 ms |
52124 KB |
Output is correct |
8 |
Correct |
13 ms |
44004 KB |
Output is correct |
9 |
Correct |
6 ms |
44004 KB |
Output is correct |
10 |
Correct |
46 ms |
47180 KB |
Output is correct |
11 |
Correct |
73 ms |
55336 KB |
Output is correct |
12 |
Correct |
13 ms |
45688 KB |
Output is correct |