#include<bits/stdc++.h>
#define lf double
#define ll long long
#define cc pair<char,char>
#define ull unsigned ll
#define ii pair<int,int>
#define li pair<ll,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define iiii2 pair<int,iii>
#define lii pair<ll,ii>
#define lolo pair<ll,ll>
#define heap priority_queue
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(),x.end()
#define len(x) strlen(x)
#define sz(x) (int) x.size()
#define orta ((bas+son)/2)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)
#define umin(x,y) x=min(x,y)
#define umax(x,y) x=max(x,y)
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define MOD 1000000000
#define inf 1000000005
#define N 300005
#define LOG 20
#define magic 100
#define KOK 250
#define EPS 0.0025
#define pw(x) (1<<(x))
#define PI 3.1415926535
using namespace std;
int tot=2,n,now;
int nxt[N][26],link[N],lazy[N],len[N];
char s[N];
ll ans;
stack<int> stc;
void add(int ind) {
while(s[ind-len[now]-1]!=s[ind]) now=link[now];
if(nxt[now][s[ind]-'a']) {
now=nxt[now][s[ind]-'a'];
lazy[now]++;
return ;
}
int nw=++tot;
nxt[now][s[ind]-'a']=nw;
len[nw]=len[now]+2;
stc.push(nw);
lazy[nw]++;
if(len[nw]==1) {
link[nw]=2;
now=nw;
return ;
}
now=link[now];
while(s[ind-len[now]-1]!=s[ind]) now=link[now];
link[nw]=nxt[now][s[ind]-'a'];
now=nw;
}
int main() {
#if 0
freopen("input.txt","r",stdin);
#endif
scanf("%s",s+1);
n=strlen(s+1);
link[1]=1;link[2]=1;
len[1]=-1;len[2]=0;
now=1;
for(int i=1;i<=n;i++) add(i);
while(!stc.empty()) {
int x=stc.top();
stc.pop();
ans=max(ans,1ll*len[x]*lazy[x]);
lazy[link[x]]++;
}
printf("%lld",ans);
}
Compilation message
palindrome.cpp: In function 'int main()':
palindrome.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
2 ms |
608 KB |
Output is correct |
4 |
Correct |
3 ms |
696 KB |
Output is correct |
5 |
Correct |
2 ms |
696 KB |
Output is correct |
6 |
Correct |
2 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Incorrect |
2 ms |
936 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
12788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
36964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |