#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
using ll = int;
using pll = pair<ll, ll>;
const int N = 3e5+5;
const int mod = 1e9+7;
int n, m, k, now, suff;
long long ans;
string s;
struct node
{
ll num, len, slink, nxt[26];
vector<ll> e;
}tree[N];
void init()
{
now = suff = 2;
tree[1].len = -1;
tree[1].slink = 1;
tree[1].e.pb(2);
tree[2].len = 0;
tree[2].slink = 1;
}
void add(int pos)
{
int c = s[pos] - 'a';
int cur = suff, curlen = 0;
while(true)
{
curlen = tree[cur].len;
if(pos-curlen-1 >= 0 && s[pos-curlen-1] == s[pos])break;
cur = tree[cur].slink;
}
if(tree[cur].nxt[c])
{
suff = tree[cur].nxt[c];
++tree[suff].num;
return;
}
++now;
suff = now;
tree[now].len = tree[cur].len + 2;
tree[now].num = 1;
tree[cur].nxt[c] = now;
if(tree[now].len == 1)
{
tree[2].e.pb(now);
tree[now].slink = 2;
return;
}
while(true)
{
cur = tree[cur].slink;
curlen = tree[cur].len;
if(pos-curlen-1 >= 0 && s[pos-curlen-1] == s[pos])break;
}
tree[now].slink = tree[cur].nxt[c];
tree[tree[now].slink].e.pb(now);
}
void dfs(ll u)
{
for(ll v : tree[u].e)
{
dfs(v);
tree[u].num += tree[v].num;
}
ans = max(ans, 1ll*tree[u].num * tree[u].len);
}
void sol()
{
cin >> s;
init();
for(int i = 0; i < s.length(); i ++)add(i);
dfs(1);
cout << ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
sol();
}
Compilation message
palindrome.cpp: In function 'void sol()':
palindrome.cpp:77:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i = 0; i < s.length(); i ++)add(i);
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
42484 KB |
Output is correct |
2 |
Correct |
21 ms |
42492 KB |
Output is correct |
3 |
Correct |
21 ms |
42500 KB |
Output is correct |
4 |
Correct |
20 ms |
42484 KB |
Output is correct |
5 |
Correct |
21 ms |
42516 KB |
Output is correct |
6 |
Correct |
21 ms |
42540 KB |
Output is correct |
7 |
Correct |
20 ms |
42572 KB |
Output is correct |
8 |
Correct |
22 ms |
42552 KB |
Output is correct |
9 |
Correct |
20 ms |
42572 KB |
Output is correct |
10 |
Correct |
20 ms |
42572 KB |
Output is correct |
11 |
Correct |
21 ms |
42540 KB |
Output is correct |
12 |
Correct |
20 ms |
42580 KB |
Output is correct |
13 |
Correct |
20 ms |
42572 KB |
Output is correct |
14 |
Correct |
20 ms |
42572 KB |
Output is correct |
15 |
Correct |
21 ms |
42572 KB |
Output is correct |
16 |
Correct |
20 ms |
42500 KB |
Output is correct |
17 |
Correct |
20 ms |
42556 KB |
Output is correct |
18 |
Correct |
21 ms |
42572 KB |
Output is correct |
19 |
Correct |
21 ms |
42464 KB |
Output is correct |
20 |
Correct |
20 ms |
42580 KB |
Output is correct |
21 |
Correct |
20 ms |
42544 KB |
Output is correct |
22 |
Correct |
20 ms |
42572 KB |
Output is correct |
23 |
Correct |
22 ms |
42544 KB |
Output is correct |
24 |
Correct |
20 ms |
42572 KB |
Output is correct |
25 |
Correct |
21 ms |
42504 KB |
Output is correct |
26 |
Correct |
20 ms |
42512 KB |
Output is correct |
27 |
Correct |
21 ms |
42512 KB |
Output is correct |
28 |
Correct |
21 ms |
42572 KB |
Output is correct |
29 |
Correct |
22 ms |
42656 KB |
Output is correct |
30 |
Correct |
19 ms |
42572 KB |
Output is correct |
31 |
Correct |
21 ms |
42528 KB |
Output is correct |
32 |
Correct |
21 ms |
42480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
42584 KB |
Output is correct |
2 |
Correct |
20 ms |
42572 KB |
Output is correct |
3 |
Correct |
21 ms |
42572 KB |
Output is correct |
4 |
Correct |
21 ms |
42572 KB |
Output is correct |
5 |
Correct |
21 ms |
42636 KB |
Output is correct |
6 |
Correct |
21 ms |
42664 KB |
Output is correct |
7 |
Correct |
21 ms |
42580 KB |
Output is correct |
8 |
Correct |
21 ms |
42584 KB |
Output is correct |
9 |
Correct |
21 ms |
42572 KB |
Output is correct |
10 |
Correct |
21 ms |
42564 KB |
Output is correct |
11 |
Correct |
21 ms |
42508 KB |
Output is correct |
12 |
Correct |
21 ms |
42572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
43120 KB |
Output is correct |
2 |
Correct |
23 ms |
43084 KB |
Output is correct |
3 |
Correct |
24 ms |
43472 KB |
Output is correct |
4 |
Correct |
23 ms |
43360 KB |
Output is correct |
5 |
Correct |
20 ms |
42680 KB |
Output is correct |
6 |
Correct |
21 ms |
42844 KB |
Output is correct |
7 |
Correct |
22 ms |
42964 KB |
Output is correct |
8 |
Correct |
21 ms |
42488 KB |
Output is correct |
9 |
Correct |
21 ms |
42572 KB |
Output is correct |
10 |
Correct |
21 ms |
42668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
48972 KB |
Output is correct |
2 |
Correct |
33 ms |
47568 KB |
Output is correct |
3 |
Correct |
38 ms |
52036 KB |
Output is correct |
4 |
Correct |
35 ms |
49852 KB |
Output is correct |
5 |
Correct |
42 ms |
43912 KB |
Output is correct |
6 |
Correct |
30 ms |
44784 KB |
Output is correct |
7 |
Correct |
31 ms |
46088 KB |
Output is correct |
8 |
Correct |
22 ms |
42828 KB |
Output is correct |
9 |
Correct |
24 ms |
44764 KB |
Output is correct |
10 |
Correct |
34 ms |
43728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
61868 KB |
Output is correct |
2 |
Correct |
56 ms |
55104 KB |
Output is correct |
3 |
Correct |
67 ms |
71244 KB |
Output is correct |
4 |
Correct |
54 ms |
59368 KB |
Output is correct |
5 |
Correct |
80 ms |
47584 KB |
Output is correct |
6 |
Correct |
55 ms |
54368 KB |
Output is correct |
7 |
Correct |
53 ms |
52116 KB |
Output is correct |
8 |
Correct |
26 ms |
43436 KB |
Output is correct |
9 |
Correct |
26 ms |
43504 KB |
Output is correct |
10 |
Correct |
68 ms |
46676 KB |
Output is correct |
11 |
Correct |
58 ms |
55628 KB |
Output is correct |
12 |
Correct |
29 ms |
45680 KB |
Output is correct |