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;
const int N = 3000*100+7;
long long h1[N],h2[N];
long long p[N];
long long hashcode1(int l,int r){
return h1[r]-h1[l-1]*p[r-l+1];
}
long long hashcode2(int l,int r){
return h2[r]-h2[l-1]*p[r-l+1];
}
int main()
{
string s;
cin>>s;
int n = s.length();
p[0] = 1;
for(int i = 1;i<=n;i++) p[i] = p[i-1]*259;
string srev = s;
reverse(srev.begin(),srev.end());
for(int i = 1;i<=n;i++){
h1[i] = h1[i-1]*259+s[i-1];
h2[i] = h2[i-1]*259+srev[i-1];
}
unordered_map<long long,int> mp;
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = i;j<=n;j++){
long long x = hashcode1(i,j);
int jj = n-i+1;
int ii = n-j+1;
long long y = hashcode2(ii,jj);
if(x == y){
mp[x]++;
ans = max(ans,(j-i+1)*mp[x]);
}
}
}
cout<<ans<<endl;
return 0;
}
# | 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... |