This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int h=71, mod = 1e9 + 7;
signed main()
{
string s;
cin>>s;
int n=s.size();
int ha[n][n];
bool dp[n][n];
int ans=0;
int cn[26]={},ct[26]={};
for (int i=0;i<n;i++)
{
int x=0;
for (int j=i;j<n;j++)
{
x*=h,x+=s[j],x%=mod;
ha[i][j]=x;
}
dp[i][i]=1;
ans=max(ans,++cn[s[i]-'a']);
if (i)
dp[i-1][i]=(s[i-1]==s[i]);
if (i and dp[i-1][i])
ans=max(ans,(++ct[s[i-1]-'a'])*2);
}
for (int len=2;len<n;len++)
{
unordered_map<int,int> cnt;
for (int i=0;i+len<n;i++)
{
int j=i+len;
dp[i][j]=dp[i+1][j-1]&(s[i]==s[j]);
if (dp[i][j])
ans=max(ans,(len+1)*(++cnt[ha[i][j]]));
}
}
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... |