#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
const int N=3e5+5;
int suff[N],len[N],lz[N],nxt[N][26],cur,tt=3;
LL ans;
string s;
stack<int> st;
void add(int x) {
while(s[x-len[cur]-1]!=s[x])
cur=suff[cur];
int y=s[x]-'a';
if(nxt[cur][y]) {
cur=nxt[cur][y];
++lz[cur];
return;
}
int nw=tt++;
st.push(nw);
++lz[nw];
len[nw]=len[cur]+2;
if(len[nw]==1) {
suff[nw]=2;
nxt[cur][y]=nw;
cur=nw;
return;
}
int tmp2=cur;
cur=suff[cur];
while(s[x-len[cur]-1]!=s[x])
cur=suff[cur];
suff[nw]=nxt[cur][y];
cur=nw;
nxt[tmp2][y]=cur;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>s;
len[1]=-1; suff[1]=1;
len[2]=0; suff[2]=1;
cur=1;
for(int i=0;i<s.size();++i)
add(i);
while(!st.empty()) {
int x=st.top();
st.pop();
ans=max(ans,1LL*len[x]*lz[x]);
lz[suff[x]]+=lz[x];
}
cout<<ans<<endl;
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();++i)
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
36164 KB |
Output is correct |
2 |
Correct |
0 ms |
36164 KB |
Output is correct |
3 |
Correct |
0 ms |
36164 KB |
Output is correct |
4 |
Correct |
0 ms |
36164 KB |
Output is correct |
5 |
Correct |
0 ms |
36164 KB |
Output is correct |
6 |
Correct |
0 ms |
36164 KB |
Output is correct |
7 |
Correct |
0 ms |
36164 KB |
Output is correct |
8 |
Correct |
0 ms |
36164 KB |
Output is correct |
9 |
Correct |
0 ms |
36164 KB |
Output is correct |
10 |
Correct |
0 ms |
36164 KB |
Output is correct |
11 |
Correct |
0 ms |
36164 KB |
Output is correct |
12 |
Correct |
0 ms |
36164 KB |
Output is correct |
13 |
Correct |
0 ms |
36164 KB |
Output is correct |
14 |
Correct |
0 ms |
36164 KB |
Output is correct |
15 |
Correct |
0 ms |
36164 KB |
Output is correct |
16 |
Correct |
0 ms |
36164 KB |
Output is correct |
17 |
Correct |
0 ms |
36164 KB |
Output is correct |
18 |
Correct |
0 ms |
36164 KB |
Output is correct |
19 |
Correct |
0 ms |
36164 KB |
Output is correct |
20 |
Correct |
0 ms |
36164 KB |
Output is correct |
21 |
Correct |
0 ms |
36164 KB |
Output is correct |
22 |
Correct |
0 ms |
36164 KB |
Output is correct |
23 |
Correct |
0 ms |
36164 KB |
Output is correct |
24 |
Correct |
0 ms |
36164 KB |
Output is correct |
25 |
Correct |
0 ms |
36164 KB |
Output is correct |
26 |
Correct |
0 ms |
36164 KB |
Output is correct |
27 |
Correct |
0 ms |
36164 KB |
Output is correct |
28 |
Correct |
0 ms |
36164 KB |
Output is correct |
29 |
Correct |
0 ms |
36164 KB |
Output is correct |
30 |
Correct |
0 ms |
36164 KB |
Output is correct |
31 |
Correct |
0 ms |
36164 KB |
Output is correct |
32 |
Correct |
0 ms |
36164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
36164 KB |
Output is correct |
2 |
Correct |
0 ms |
36164 KB |
Output is correct |
3 |
Correct |
0 ms |
36164 KB |
Output is correct |
4 |
Correct |
0 ms |
36164 KB |
Output is correct |
5 |
Correct |
0 ms |
36164 KB |
Output is correct |
6 |
Correct |
0 ms |
36164 KB |
Output is correct |
7 |
Correct |
0 ms |
36164 KB |
Output is correct |
8 |
Correct |
0 ms |
36164 KB |
Output is correct |
9 |
Correct |
0 ms |
36164 KB |
Output is correct |
10 |
Correct |
0 ms |
36164 KB |
Output is correct |
11 |
Correct |
0 ms |
36164 KB |
Output is correct |
12 |
Correct |
0 ms |
36164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
36164 KB |
Output is correct |
2 |
Correct |
0 ms |
36164 KB |
Output is correct |
3 |
Correct |
0 ms |
36164 KB |
Output is correct |
4 |
Correct |
0 ms |
36164 KB |
Output is correct |
5 |
Correct |
0 ms |
36164 KB |
Output is correct |
6 |
Correct |
0 ms |
36164 KB |
Output is correct |
7 |
Correct |
0 ms |
36164 KB |
Output is correct |
8 |
Correct |
0 ms |
36164 KB |
Output is correct |
9 |
Correct |
0 ms |
36164 KB |
Output is correct |
10 |
Correct |
0 ms |
36164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
36712 KB |
Output is correct |
2 |
Correct |
6 ms |
36712 KB |
Output is correct |
3 |
Correct |
6 ms |
36712 KB |
Output is correct |
4 |
Correct |
0 ms |
36712 KB |
Output is correct |
5 |
Correct |
0 ms |
36712 KB |
Output is correct |
6 |
Correct |
3 ms |
36580 KB |
Output is correct |
7 |
Correct |
0 ms |
36580 KB |
Output is correct |
8 |
Correct |
0 ms |
36316 KB |
Output is correct |
9 |
Correct |
3 ms |
36316 KB |
Output is correct |
10 |
Correct |
6 ms |
36580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
37912 KB |
Output is correct |
2 |
Correct |
13 ms |
37912 KB |
Output is correct |
3 |
Correct |
6 ms |
37912 KB |
Output is correct |
4 |
Correct |
16 ms |
37912 KB |
Output is correct |
5 |
Correct |
19 ms |
37912 KB |
Output is correct |
6 |
Correct |
9 ms |
37780 KB |
Output is correct |
7 |
Correct |
9 ms |
37648 KB |
Output is correct |
8 |
Correct |
3 ms |
36964 KB |
Output is correct |
9 |
Correct |
3 ms |
36964 KB |
Output is correct |
10 |
Correct |
13 ms |
37648 KB |
Output is correct |
11 |
Correct |
9 ms |
37912 KB |
Output is correct |
12 |
Correct |
9 ms |
36964 KB |
Output is correct |