/*
ID: 5ak0
PROG:
LANG: C++11
*/
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int N = 300000;
string s;
int ans;
int d[N], d2[N];
int calc(string c){
int n = c.size();
int l, r;
l = r = -1;
for (int i = 0; i < n; i++)
{
d[i] = 1;
if (i <= r)
d[i] = min(r - i + 1, d[l + (r - i)]);
while (i + d[i] < n && i - d[i] >= 0 && c[i - d[i]] == c[i + d[i]])
d[i]++;
if (i + d[i] - 1 > r)
l = i - d[i] + 1, r = i + d[i] - 1;
}
l = r = -1;
for (int i = 0; i < n; i++)
{
d2[i] = 0;
if (i <= r)
d2[i] = min(r - i, d2[l + (r - i) - 1]);
while (i + d2[i] + 1 < n && i - d2[i] >= 0 && c[i - d2[i]] == c[i + d2[i] + 1])
{
d2[i]++;
}
if (i + d2[i] > r)
l = i - d2[i] + 1, r = i + d2[i];
}
long long ans = 0;
for (int i = 0; i < n; i++)
{
ans += (d[i] - 1);
ans += d2[i];
}
return ans + c.size();
}
int main(){
cin >> s;
ans = calc(s);
for (int i = 0; i < s.size(); ++i){
char ch = s[i];
for (char j = 'a'; j <= 'z'; ++j){
s[i] = j;
ans = max(ans, calc(s));
}
s[i] = ch;
}
cout << ans;
return 0;
}
Compilation message
palinilap.cpp: In function 'int main()':
palinilap.cpp:64:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < s.size(); ++i){
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4364 KB |
Output is correct |
2 |
Correct |
4 ms |
4364 KB |
Output is correct |
3 |
Correct |
4 ms |
4364 KB |
Output is correct |
4 |
Correct |
4 ms |
4364 KB |
Output is correct |
5 |
Correct |
3 ms |
4364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
4364 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1000 ms |
4680 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |