#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 600010
using namespace std;
struct PalTree{
struct Node{
int len, cnt, to[26], dub, slink;
Node() { len=0; cnt=0; dub=0; slink=0; for (int i=0; i<26; i++) to[i]=-1; }
Node(int a, int b, int c, int d)
{
len=a; cnt=b; dub=c; slink=d;
for (int i=0; i<26; i++) to[i]=-1;
}
};
vector<Node> pt;
int suff;
int s[MAXN];
int gde=0;
void addLetter(int c)
{
//cout<<gde<<" "<<suff<<endl;
s[gde]=c;
while (gde-1-pt[suff].len < 0 || c!=s[gde-1-pt[suff].len])
suff=pt[suff].slink;
//cout<<suff<<endl;
int slnd=pt[suff].to[c];
if (slnd==-1)
{
slnd=pt.size();
pt[suff].to[c]=slnd;
pt.pb(Node(pt[suff].len+2, 0, 0, 0));
if (suff==1)
pt[slnd].slink=2;
else
{
int pom=pt[suff].slink;
while(c!=s[gde-1-pt[pom].len])
pom=pt[pom].slink;
pt[slnd].slink=pt[pom].to[c];
assert(pt[pom].to[c] != -1);
//assert(pt[slnd].slink<pt.size());
}
pt[slnd].dub=pt[pt[slnd].slink].dub+1;
}
pt[slnd].cnt++;
suff=slnd;
gde++;
//cout<<slnd<<" "<<pt[slnd].slink<<endl;
}
void calc()
{
for (int i=pt.size()-1; i>2; i--){ pt[pt[i].slink].cnt+=pt[i].cnt; }
}
void init()
{
pt.clear();
pt.pb(Node(-1, -1, -1, -1));
pt.pb(Node(-1, 0, 0, 1));
pt.pb(Node(0, 0, 0, 1));
suff=2;
}
Node &operator[](int idx) {
return pt[idx];
}
};
PalTree pt;
ll ress=-1;
string st;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>st;
pt.init();
for (int i=0; i<st.size(); i++) pt.addLetter((int)(st[i]-'a'));
pt.calc();
for (int i=3; i<pt.pt.size(); i++)
{
ress=max(ress, ((ll)pt[i].cnt*pt[i].len));
}
cout<<ress;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i=0; i<st.size(); i++) pt.addLetter((int)(st[i]-'a'));
| ~^~~~~~~~~~
palindrome.cpp:92:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<PalTree::Node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int i=3; i<pt.pt.size(); i++)
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
456 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2444 KB |
Output is correct |
2 |
Correct |
2 ms |
2444 KB |
Output is correct |
3 |
Correct |
2 ms |
2444 KB |
Output is correct |
4 |
Correct |
2 ms |
2444 KB |
Output is correct |
5 |
Correct |
2 ms |
2444 KB |
Output is correct |
6 |
Correct |
2 ms |
2444 KB |
Output is correct |
7 |
Correct |
2 ms |
2316 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
1392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
16304 KB |
Output is correct |
2 |
Correct |
15 ms |
16296 KB |
Output is correct |
3 |
Correct |
15 ms |
16296 KB |
Output is correct |
4 |
Correct |
16 ms |
16284 KB |
Output is correct |
5 |
Correct |
16 ms |
16296 KB |
Output is correct |
6 |
Correct |
15 ms |
16296 KB |
Output is correct |
7 |
Correct |
14 ms |
16316 KB |
Output is correct |
8 |
Correct |
3 ms |
972 KB |
Output is correct |
9 |
Correct |
5 ms |
4784 KB |
Output is correct |
10 |
Correct |
14 ms |
16296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
63304 KB |
Output is correct |
2 |
Correct |
49 ms |
63376 KB |
Output is correct |
3 |
Correct |
52 ms |
63392 KB |
Output is correct |
4 |
Correct |
63 ms |
63316 KB |
Output is correct |
5 |
Correct |
51 ms |
63228 KB |
Output is correct |
6 |
Correct |
48 ms |
63388 KB |
Output is correct |
7 |
Correct |
36 ms |
32156 KB |
Output is correct |
8 |
Correct |
8 ms |
2176 KB |
Output is correct |
9 |
Correct |
7 ms |
2132 KB |
Output is correct |
10 |
Correct |
41 ms |
32244 KB |
Output is correct |
11 |
Correct |
50 ms |
63240 KB |
Output is correct |
12 |
Correct |
10 ms |
5636 KB |
Output is correct |