#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
string s;
cin >> s;
int n = (int)s.size();
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string t = s.substr(i, j - i + 1), p = t;
reverse(p.begin(), p.end());
cnt += (p == t);
}
}
int mx = cnt;
for (int i = 0; i < n; i++) {
int rmv = 0;
for (int j = 0; j <= i; j++) {
for (int k = i; k < n; k++) {
string t = s.substr(j, k - j + 1), p = t;
reverse(p.begin(), p.end());
rmv += (t == p);
}
}
for (char c = 'a'; c <= 'z'; c++) {
if (s[i] == c) continue;
int remsi = s[i];
s[i] = c;
int cnt2 = cnt - rmv;
for (int j = 0; j <= i; j++) {
for (int k = i; k < n; k++) {
string t = s.substr(j, k - j + 1), p = t;
reverse(p.begin(), p.end());
cnt2 += (t == p);
}
}
s[i] = remsi;
mx = max(mx, cnt2);
}
}
cout << mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
428 KB |
Output is correct |
2 |
Correct |
305 ms |
344 KB |
Output is correct |
3 |
Correct |
309 ms |
348 KB |
Output is correct |
4 |
Correct |
309 ms |
344 KB |
Output is correct |
5 |
Correct |
313 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1052 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1033 ms |
600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |