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();
- 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);
- //cout<<count(P.begin(), P.end(), 0);
- //cout<<*upper_bound(P.begin(), P.end(), 0) - *lower_bound(P.begin(), P.end(), 0);
- /*int fr, to;
- for (int i =0;i<n;++i){
- if (P[i] == 0){
- fr=i;
- break;
- }
- }
- for (int i = fr+1;i<n;++i){
- if (P[i]==0){
- to=i;
- break;
- }
- }
- cout<<to-fr+1;*/
- }
- /*
- Контрпример:
- abbbbbaaaa
- 6
- aabbbbbaaaa
- candalacadndala
- 7
- kalkulkalkulkalkulkalka
- lkulkalkulka
- akkakakkakakka
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement