#include <iostream>
using namespace std;
typedef long long ll;
string s;
int n, cnt1[100005], cnt2[100005];
ll brojpalin(){
ll ret = 0;
int l = 0, r = -1;
for(int i = 0 ; i < n ; ++i){
int k = (i > r ? 1 : min(cnt1[l + r - i], r - i + 1));
while(i - k >= 0 && i + k < n && s[i - k] == s[i + k]){
k++;
}
cnt1[i] = k--;
if(i + k > r){
l = i - k;
r = i + k;
}
ret += k + 1;
}
l = 0;
r = -1;
for(int i = 0 ; i < n ; ++i){
int k = (i > r ? 0 : min(cnt2[l + r - i + 1], r - i + 1));
while(i - k - 1 >= 0 && i + k < n && s[i - k - 1] == s[i + k]){
k++;
}
cnt2[i] = k--;
if(i + k > r){
l = i - k - 1;
r = i + k;
}
ret += k + 1;
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
n = (int)s.size();
ll sol = brojpalin();
for(int i = 0 ; i < n ; ++i){
char poc = s[i];
for(int j = 0 ; j < 26 ; ++j){
s[i] = j + 'a';
sol = max(sol, brojpalin());
}
s[i] = poc;
}
cout << sol << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
7 ms |
384 KB |
Output is correct |
5 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1077 ms |
384 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1070 ms |
1536 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |