#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
#define pb push_back
#define endl "\n"
#define sec second
#define fir first
#define print1(x) cout<<x<<endl;
#define print2(x,y) cout<<x<<": "<<y<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<vll> vvll;
const int maxn = 3e5 + 5, sigma = 26; // sigma son las letras del abc
char s[maxn]; // aqui guardamos el string
int len[maxn], link[maxn], to[maxn][sigma];
vvi edge(maxn);
vll ocurr(maxn);
int n = 0, last, sz;
// n es el tamanio acutal de la cadena, last el ultimo nodo al que accedimos
void init()
{
s[n++] = -1; // cadena imaginaria
link[0] = 1; // link suffix para palindromos pares
len[1] = -1; // longitud de palindromo imaginario
sz = 2; // tamanio actual del arbol, se comienza desde el nodo 3
edge[0].pb(1);
}
// get_link encuentra un s[n - 1] X s[n - 1] sea un palindromo
// donde X es un palindromo
int get_link(int v)
{
while(s[n - len[v] - 2] != s[n - 1]) v = link[v];
return v;
}
void add_letter(int c)
{
s[n++] = c; // agregamos una nueva letra
last = get_link(last); // obtenemos el nuevo padre para nuestro nodo
if(!to[last][c])
{
len [sz] = len[last] + 2; // actualizamos su len del nuevo nodo
link[sz] = to[get_link(link[last])][c]; // obtemos su nuevo link del nodo
edge[link[sz]].pb(sz);
to[last][c] = sz++; // nueva arista al nuevo nodo
}
last = to[last][c]; // actualizamos el ultimo nodo al q accedimos
ocurr[last]++;
}
ll ans = 0;
void dfs(int u = 0){
for(auto v : edge[u]){
dfs(v);
ocurr[u] += ocurr[v];
}
ans = max(ans, ocurr[u] * len[u]);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
init();
char c;
while((c = getchar()) != '\n'){
add_letter(c - 'a');
}
dfs();
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13912 KB |
Output is correct |
2 |
Correct |
3 ms |
13916 KB |
Output is correct |
3 |
Correct |
4 ms |
13916 KB |
Output is correct |
4 |
Correct |
3 ms |
13916 KB |
Output is correct |
5 |
Correct |
4 ms |
13988 KB |
Output is correct |
6 |
Correct |
4 ms |
13916 KB |
Output is correct |
7 |
Correct |
4 ms |
13916 KB |
Output is correct |
8 |
Correct |
4 ms |
13912 KB |
Output is correct |
9 |
Correct |
3 ms |
13912 KB |
Output is correct |
10 |
Correct |
4 ms |
13916 KB |
Output is correct |
11 |
Correct |
4 ms |
13916 KB |
Output is correct |
12 |
Correct |
4 ms |
13912 KB |
Output is correct |
13 |
Correct |
4 ms |
13916 KB |
Output is correct |
14 |
Correct |
3 ms |
13916 KB |
Output is correct |
15 |
Correct |
3 ms |
13916 KB |
Output is correct |
16 |
Correct |
4 ms |
13916 KB |
Output is correct |
17 |
Correct |
3 ms |
13916 KB |
Output is correct |
18 |
Correct |
4 ms |
13916 KB |
Output is correct |
19 |
Correct |
4 ms |
13752 KB |
Output is correct |
20 |
Correct |
4 ms |
13916 KB |
Output is correct |
21 |
Correct |
4 ms |
13916 KB |
Output is correct |
22 |
Correct |
4 ms |
13916 KB |
Output is correct |
23 |
Correct |
4 ms |
13916 KB |
Output is correct |
24 |
Correct |
4 ms |
13916 KB |
Output is correct |
25 |
Correct |
4 ms |
13916 KB |
Output is correct |
26 |
Correct |
3 ms |
13912 KB |
Output is correct |
27 |
Correct |
3 ms |
13916 KB |
Output is correct |
28 |
Correct |
4 ms |
13980 KB |
Output is correct |
29 |
Correct |
3 ms |
13996 KB |
Output is correct |
30 |
Correct |
5 ms |
13916 KB |
Output is correct |
31 |
Correct |
4 ms |
13976 KB |
Output is correct |
32 |
Correct |
4 ms |
13916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13916 KB |
Output is correct |
2 |
Correct |
5 ms |
13916 KB |
Output is correct |
3 |
Correct |
3 ms |
13916 KB |
Output is correct |
4 |
Correct |
3 ms |
13916 KB |
Output is correct |
5 |
Correct |
4 ms |
14172 KB |
Output is correct |
6 |
Correct |
4 ms |
13916 KB |
Output is correct |
7 |
Correct |
3 ms |
13916 KB |
Output is correct |
8 |
Correct |
5 ms |
13916 KB |
Output is correct |
9 |
Correct |
4 ms |
13916 KB |
Output is correct |
10 |
Correct |
4 ms |
13916 KB |
Output is correct |
11 |
Correct |
5 ms |
13916 KB |
Output is correct |
12 |
Correct |
4 ms |
13916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
15452 KB |
Output is correct |
2 |
Correct |
6 ms |
15960 KB |
Output is correct |
3 |
Correct |
5 ms |
15708 KB |
Output is correct |
4 |
Correct |
5 ms |
15704 KB |
Output is correct |
5 |
Correct |
6 ms |
15192 KB |
Output is correct |
6 |
Correct |
6 ms |
15192 KB |
Output is correct |
7 |
Correct |
7 ms |
15196 KB |
Output is correct |
8 |
Correct |
4 ms |
13916 KB |
Output is correct |
9 |
Correct |
4 ms |
13988 KB |
Output is correct |
10 |
Correct |
5 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
30300 KB |
Output is correct |
2 |
Correct |
14 ms |
29020 KB |
Output is correct |
3 |
Correct |
19 ms |
33628 KB |
Output is correct |
4 |
Correct |
16 ms |
31320 KB |
Output is correct |
5 |
Correct |
14 ms |
25156 KB |
Output is correct |
6 |
Correct |
14 ms |
23384 KB |
Output is correct |
7 |
Correct |
13 ms |
25948 KB |
Output is correct |
8 |
Correct |
5 ms |
14168 KB |
Output is correct |
9 |
Correct |
8 ms |
18328 KB |
Output is correct |
10 |
Correct |
13 ms |
23644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
61860 KB |
Output is correct |
2 |
Correct |
37 ms |
55124 KB |
Output is correct |
3 |
Correct |
49 ms |
71608 KB |
Output is correct |
4 |
Correct |
39 ms |
59216 KB |
Output is correct |
5 |
Correct |
49 ms |
47728 KB |
Output is correct |
6 |
Correct |
36 ms |
52572 KB |
Output is correct |
7 |
Correct |
34 ms |
48736 KB |
Output is correct |
8 |
Correct |
7 ms |
14428 KB |
Output is correct |
9 |
Correct |
8 ms |
14680 KB |
Output is correct |
10 |
Correct |
35 ms |
42840 KB |
Output is correct |
11 |
Correct |
41 ms |
55644 KB |
Output is correct |
12 |
Correct |
11 ms |
19800 KB |
Output is correct |