-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanacher.cpp
66 lines (57 loc) · 1.36 KB
/
manacher.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
In the name of ALLAH
Author : Raashid Anwar
*/
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
const int M1 = 998244353;
const int M2 = 1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
class manacher {
int start, end;
vector <int> table;
string s;
public :
manacher(string _s) : s(_s) {
int n = s.size();
n += n + 1;
table.resize(n);
table[1] = 1;
int R = 2, C = 1, index = 0;
for(int i = 2; i < n; i++) {
if(R - i > 0)
table[i] = min(table[2 * C - i], R - i);
while(((i + table[i]) < n) && ((i - table[i]) > 0)) {
if(!((i + table[i] + 1) & 1) || (s[(i + table[i] + 1)/2] == s[(i - table[i] - 1)/2]))
table[i]++;
else
break;
}
if(table[i] > table[index])
index = i;
if(i + table[i] > R) {
C = i;
R = i + table[i];
}
}
start = (index - table[index]) / 2;
end = start + table[index] - 1;
};
string longest_palindrome() {
return s.substr(start, end - start + 1);
}
pair <int, int> getindex() {
return {start, end};
};
vector <int> gettable() {
return table;
}
};
void solve() {
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}