Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string S; cin>>S; int n = S.size();
- pii lr; int l,r;
- vector <int> P(n, 0);
- for (int i = 1; i <n;++i){
- int j = P[i-1];
- while (j > 0 && S[j] != S[i]){
- j = P[j-1];
- }
- if (S[i] == S[j]){
- ++j;
- }
- P[i] = j;
- }
- cv(P);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement