# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134903 | wmrmr | Palindromes (APIO14_palindrome) | C++17 | 0 ms | 0 KiB |
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;
long long int ans;
map<string,int> m;
map<string,int>::iterator mit;
string s;
void ImpInsert()
{
int tam = s.size();
for(int i=0;i<tam;i++)
{
string aux;
int maxt = min( i+1, tam-i );
for(int j=0;j<maxt;j++)
{
if( s[i+j] != s[i-j] ) break;
aux.push_back(s[i+j]);
if(m.find(aux) == m.end()) m.insert({aux,1});
else m[aux]++;
}
}
return;
}
void PairInsert()
{
int tam = s.size();
for(int i=1;i<tam;i++)
{
string aux;
int maxt = min(i,tam-i)
{
for(int j=0;j<maxt;j++)
{
if(s[i-1-j] != s[i+j]) break;
aux.push_back(s[i+j]);
if(m.find(aux) == m.end()) m.insert({aux,1});
else m[aux]++;
}
}
}
}
int main()
{
cin >> s;
ImpInsert();
for(mit = m.begin();mit!=m.end();mit++)
{
int tam = (mit->first).size(), qtd = mit->second;
ans = max( ans , (long long int) qtd*(2*tam-1) );
}
m.clear();
PairInsert();
for(mit = m.begin();mit!=m.end();mit++)
{
int tam = (mit->first).size(), qtd = mit->second;
ans = max( ans , (long long int) qtd*(2*tam) );
}
printf("%lld",ans);
}