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 ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
const ll N = 5005;
const ll M = 1e9 + 7;
int a[N][N];
int f(char c){
return (c-'a');
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
string s;
cin >> s;
int n = sz(s);
int ans = 0;
for(int i = 0; i < n; i++){
int l = i, r = i, l1, r1;
bool tr = 0;
while(l >= 0 and r < n){
if(s[l] == s[r]){
if(tr == 0){
ans++;
}
else {
a[l1][f(s[r1])]++;
a[r1][f(s[l1])]++;
}
}
else {
if(tr == 1) break;
tr = 1;
l1 = l, r1 = r;
a[l][f(s[r])]++;
a[r][f(s[l])]++;
}
l--;
r++;
}
}
for(int i = 0; i < n-1; i++){
int l = i, r = i+1, l1, r1;
bool tr = 0;
while(l >= 0 and r < n){
if(s[l] == s[r]){
if(tr == 0){
ans++;
}
else {
a[l1][f(s[r1])]++;
a[r1][f(s[l1])]++;
}
}
else {
if(tr == 1) break;
tr = 1;
l1 = l, r1 = r;
a[l][f(s[r])]++;
a[r][f(s[l])]++;
}
l--;
r++;
}
}
int mx = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < 26; j++){
mx = max(mx,a[i][j]);
}
}
cout << ans + mx;
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... |