-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstring_kmp.cpp
55 lines (48 loc) · 1018 Bytes
/
string_kmp.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
/*
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 string_kmp {
int n;
vector <int> lsp;
string p;
public :
string_kmp(int _n, const string& p): n(_n), p(p) {
lsp.resize(n, 0);
for (int i = 1, l = 0; i < n; i++) {
while (l && p[i] != p[l]) {
l = lsp[l - 1];
}
if (p[i] == p[l]) {
lsp[i] = ++l;
}
}
}
bool is_found(const string& s) {
int m = s.size() - 1;
for (int i = 0, j = 0; i < m; i++) {
while (j && s[i] != p[j]) {
j = lsp[j - 1];
}
if(s[i] == p[j]) {
if (++j == n) {
return true;
}
}
}
return false;
}
};
void solve() {
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
}