-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13275.cpp
More file actions
39 lines (35 loc) · 686 Bytes
/
13275.cpp
File metadata and controls
39 lines (35 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MAX = 200002;
int A[MAX];
void manachers(string s) {
int r = 0, p = 0;
int n = s.size();
for (int i = 0; i < n; i++) {
if (i <= r)
A[i] = min(A[2 * p - i], r - i);
else
A[i] = 0;
while (i - A[i] - 1 >= 0 && i + A[i] + 1 < n && s[i - A[i] - 1] == s[i + A[i] + 1])
A[i]++;
if (r < i + A[i]) {
r = i + A[i];
p = i;
}
}
}
int main() {
string s, tmp = "#";
int answer = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
tmp += s[i];
tmp += "#";
}
manachers(tmp);
for (int i = 0; i < tmp.size(); i++)
answer = max(answer, A[i]);
cout << answer << "\n";
}