bichnhb
Giới thiệu
include <bits/stdc++.h>
using namespace std;
int n, L, R, M;
string s;
int P[10004];
int tim(int k)
{
int dem, d, c;
if(k%2==0) dem = 0;
else dem = 1;
d = k/2-1;
c = k-1-d;
while(d>=0 && c<n)
{
if(s[d]==s[c]) dem = dem + 1;
else break;
d = d-1;
c = c+1;
}
L = d++;
R = c--;
M = k;
return dem;
}
int main()
{
//freopen("maxpalin.inp","r",stdin);
//freopen("maxpalin.out","w",stdout);
cin >> n >> s;
int m = 2n;
fill(P,P+10004,0);
P[1] = 1;
P[m-1] = 1;
L=1; R=0;
for(int i=2; i<=m-2; i++)
{
if(i>=R) P[i] = tim(i);
else
{
int dx = M - (i-M);
if(P[dx]<M-L) P[i]=P[dx];
else P[i] = tim(i);
}
}
int maxx = 1, vt = 1;
for(int i=1; i<=m-1; i++)
if(maxx<P[i]) { maxx=P[i]; vt = i;}
if (vt%2==1)
cout << 2maxx-1;
else cout << 2*maxx;
return 0;
}