#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846
int p=-1, ch;
string s;
struct node{
node* c[27];
node* fail;
vector<node*> nxt;
int cnt, len;
node(){
cnt=0; len=-1; fail=0;
fox(l, 26){c[l]=0;}
nxt=vector<node*>();
}
node(node*P){
//cout << "^" << P->len << endl;
len=0; cnt=0;
fox(l, 26) c[l]=0;
P->nxt.pb(this);
fail=P;
}
node(node*P, int L){
//cout << "&";
len=L; cnt=0;
fox(l, 26) c[l]=0;
if (L>1){
P=P->fail;
while(p-1-P->len<0 || s[p-1-P->len]!=s[p]) P=P->fail;
P=P->c[ch];
}
P->nxt.pb(this);
fail=P;
}
}*root, *r2, *last;
void add(node*N){
while(p-1-N->len<0 || s[p-1-N->len]!=s[p]){
N=N->fail;
}
//cout << "*" << N->len << endl;
if (N->c[ch]==0){
if (N->len==-1) N->c[ch]=new node(r2, 1);
else N->c[ch]=new node(N, N->len+2);
}
last=N->c[ch];
N->c[ch]->cnt++;
}
ll ans;
void dfs(node*N){
fox(l, N->nxt.size()){
dfs(N->nxt[l]);
N->cnt+=N->nxt[l]->cnt;
}
ans=max(ans, 1LL*N->cnt*N->len);
}
int main(){
root=new node();
last=r2=new node(root);
cin >> s;
for(p=0; p<s.size(); ++p){
ch=s[p]-'a';
add(last);
//cout << p << endl;
}
dfs(root);
cout << ans;
return 0;
}
Compilation message
palindrome.cpp: In function 'void dfs(node*)':
palindrome.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define fox(k, x) for (int k=0; k<x; ++k)
^
palindrome.cpp:76:5: note: in expansion of macro 'fox'
fox(l, N->nxt.size()){
^
palindrome.cpp: In function 'int main()':
palindrome.cpp:86:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(p=0; p<s.size(); ++p){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2020 KB |
Output is correct |
2 |
Correct |
0 ms |
2020 KB |
Output is correct |
3 |
Correct |
0 ms |
2020 KB |
Output is correct |
4 |
Correct |
0 ms |
2020 KB |
Output is correct |
5 |
Correct |
0 ms |
2020 KB |
Output is correct |
6 |
Correct |
0 ms |
2020 KB |
Output is correct |
7 |
Correct |
0 ms |
2020 KB |
Output is correct |
8 |
Correct |
0 ms |
2020 KB |
Output is correct |
9 |
Correct |
0 ms |
2020 KB |
Output is correct |
10 |
Correct |
0 ms |
2020 KB |
Output is correct |
11 |
Correct |
0 ms |
2020 KB |
Output is correct |
12 |
Correct |
0 ms |
2020 KB |
Output is correct |
13 |
Correct |
0 ms |
2020 KB |
Output is correct |
14 |
Correct |
0 ms |
2020 KB |
Output is correct |
15 |
Correct |
0 ms |
2020 KB |
Output is correct |
16 |
Correct |
0 ms |
2020 KB |
Output is correct |
17 |
Correct |
0 ms |
2020 KB |
Output is correct |
18 |
Correct |
0 ms |
2020 KB |
Output is correct |
19 |
Correct |
0 ms |
2020 KB |
Output is correct |
20 |
Correct |
0 ms |
2020 KB |
Output is correct |
21 |
Correct |
0 ms |
2020 KB |
Output is correct |
22 |
Correct |
0 ms |
2020 KB |
Output is correct |
23 |
Correct |
0 ms |
2020 KB |
Output is correct |
24 |
Correct |
0 ms |
2020 KB |
Output is correct |
25 |
Correct |
0 ms |
2020 KB |
Output is correct |
26 |
Correct |
0 ms |
2020 KB |
Output is correct |
27 |
Correct |
0 ms |
2020 KB |
Output is correct |
28 |
Correct |
0 ms |
2020 KB |
Output is correct |
29 |
Correct |
0 ms |
2020 KB |
Output is correct |
30 |
Correct |
0 ms |
2020 KB |
Output is correct |
31 |
Correct |
0 ms |
2020 KB |
Output is correct |
32 |
Correct |
0 ms |
2020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2284 KB |
Output is correct |
2 |
Correct |
1 ms |
2284 KB |
Output is correct |
3 |
Correct |
0 ms |
2284 KB |
Output is correct |
4 |
Correct |
1 ms |
2284 KB |
Output is correct |
5 |
Correct |
0 ms |
2284 KB |
Output is correct |
6 |
Correct |
1 ms |
2284 KB |
Output is correct |
7 |
Correct |
0 ms |
2284 KB |
Output is correct |
8 |
Correct |
1 ms |
2284 KB |
Output is correct |
9 |
Correct |
1 ms |
2284 KB |
Output is correct |
10 |
Correct |
0 ms |
2020 KB |
Output is correct |
11 |
Correct |
0 ms |
2020 KB |
Output is correct |
12 |
Correct |
0 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5084 KB |
Output is correct |
2 |
Correct |
1 ms |
5056 KB |
Output is correct |
3 |
Correct |
5 ms |
5244 KB |
Output is correct |
4 |
Correct |
2 ms |
5192 KB |
Output is correct |
5 |
Correct |
2 ms |
4924 KB |
Output is correct |
6 |
Correct |
0 ms |
4924 KB |
Output is correct |
7 |
Correct |
5 ms |
5056 KB |
Output is correct |
8 |
Correct |
1 ms |
2152 KB |
Output is correct |
9 |
Correct |
1 ms |
2152 KB |
Output is correct |
10 |
Correct |
3 ms |
4000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
33344 KB |
Output is correct |
2 |
Correct |
23 ms |
32656 KB |
Output is correct |
3 |
Correct |
35 ms |
34900 KB |
Output is correct |
4 |
Correct |
34 ms |
33772 KB |
Output is correct |
5 |
Correct |
37 ms |
30452 KB |
Output is correct |
6 |
Correct |
34 ms |
23324 KB |
Output is correct |
7 |
Correct |
29 ms |
27328 KB |
Output is correct |
8 |
Correct |
6 ms |
2468 KB |
Output is correct |
9 |
Correct |
7 ms |
9640 KB |
Output is correct |
10 |
Correct |
24 ms |
26228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
96108 KB |
Output is correct |
2 |
Correct |
79 ms |
92748 KB |
Output is correct |
3 |
Correct |
84 ms |
100800 KB |
Output is correct |
4 |
Correct |
96 ms |
94820 KB |
Output is correct |
5 |
Correct |
114 ms |
87720 KB |
Output is correct |
6 |
Correct |
106 ms |
82508 KB |
Output is correct |
7 |
Correct |
84 ms |
76800 KB |
Output is correct |
8 |
Correct |
13 ms |
2976 KB |
Output is correct |
9 |
Correct |
13 ms |
2976 KB |
Output is correct |
10 |
Correct |
87 ms |
72012 KB |
Output is correct |
11 |
Correct |
119 ms |
92988 KB |
Output is correct |
12 |
Correct |
18 ms |
11752 KB |
Output is correct |