This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
#define SZ(x) (int)(x).size()
const int mod=1e9+7;
int qpow(int x,int t){
if(t==0){return 1;}
if(t%2==1){return qpow(x,t-1)*x%mod;}
int xx=qpow(x,t/2);
return xx*xx%mod;
}
int tme[500005];
struct rlhsh{
vector<int>hsh;
int n;
void init(string s){
n=s.size();
hsh.resize(s.size()+10,0);
for(int i=1;i<=n;i++){
hsh[i]=(hsh[i-1]+(s[i-1]-'a')*tme[i])%mod;
}
}
int gthsh(int l,int r){
int ret=(hsh[r]-hsh[l-1]+mod)*qpow(tme[l-1],mod-2)%mod;
return ret;
}
};
int n;
pair<int,int>rev(int l,int r){
l=n-l+1;r=n-r+1;
swap(l,r);
return {l,r};
}
string s;
signed main(){
tme[0]=1;
for(int i=1;i<=500000;i++){
tme[i]=tme[i-1]*37%mod;
}
cin>>s;
n=s.size();
rlhsh sh;
sh.init(s);
reverse(s.begin(),s.end());
rlhsh rsh;
rsh.init(s);
int ans=1;
map<int,int>mp;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
int v=sh.gthsh(i,j);
if(v==rsh.gthsh(n-j+1,n-i+1)){
mp[v]++;
ans=max(ans,mp[v]*(j-i+1));
}
}
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |