-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13275.cpp
41 lines (36 loc) · 818 Bytes
/
13275.cpp
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
40
41
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
cin.tie(nullptr);
cout.tie(nullptr);
ios::sync_with_stdio(false);
string temp; cin >> temp;
int n = temp.size() * 2 + 1;
char str[n];
for (int i = 0; i < temp.size(); i++)
{
str[i * 2] = '*';
str[i * 2 + 1] = temp[i];
}
str[n - 1] = '*';
int dp[n]; for (int i = 0; i < n; i++) dp[i] = 1;
int result = 1;
int c = 0, r = 0;
for (int i = 0; i < n; i++) {
int radius = min(r - i, dp[c * 2 - i]);
while (i - radius >= 0 && i + radius < n && str[i - radius] == str[i + radius]) radius++;
radius--;
dp[i] = radius;
if (r <= i + radius) {
r = i + radius;
c = i;
}
result = max(result, radius);
}
cout << result;
return 0;
}