Skip to content

Instantly share code, notes, and snippets.

@pagodepaiva
Created January 22, 2023 17:56
Show Gist options
  • Save pagodepaiva/0e9aba2aada9274c9186e84e6f5e3d5a to your computer and use it in GitHub Desktop.
Save pagodepaiva/0e9aba2aada9274c9186e84e6f5e3d5a to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
#define int long long
#define ms(v) memset(v, -1, sizeof v)
#define pb push_back
#define mp make_pair
#define ll long long int
#define pi pair <int,int>
#define itn int
#define fr first
#define sc second
#define srt(v) sort(v.begin(), v.end())
#define rvs(v) reverse(v.begin(), v.end())
#define mod 1000000007
#define N 510
using namespace std;
int n;
char v[N];
main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 0;i < n;i++) cin >> v[i];
int res = 0;
//palindromos de tamanho impar
for(int i = 0;i < n;i++){
int aux = 1;
int sz = 1;
for(int j = i-1;j >= 0;j--){
if(v[i-sz] != v[i+sz]) break;
aux += 2;
sz++;
}
res = max(res, aux);
}
//palindromos de tamanho par
for(int i = 0;i < n;i++){
int aux = 0;
int sz = 0;
for(int j = i;j >= 0;j--){
if(v[i-sz] != v[i+sz+1]) break;
aux += 2;
sz++;
}
res = max(res, aux);
}
cout << res << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment