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 a,b; cin>>a>>b;
- int n = a.size() + b.size() + 1;
- string S = b + "#" + a;
- vector <int> Z(n, 0);
- pii lr = {-2e9, -2e9};
- int l,r;
- //cout<<"S = "<<S<<"\n";
- for (int i = 1; i < n;++i){
- if (i <= lr.second){
- Z[i] = min(lr.second - i + 1, Z[i - lr.first ]);
- }
- while (i + Z[i] < n && S[i + Z[i]] == S[Z[i]]){
- ++Z[i];
- }
- r = i + Z[i] - 1;
- l = i;
- if (r > lr.second){
- lr = {l, r};
- }
- }
- vector <int> ans;
- for (int i = 0; i < n;++i){
- if (Z[i] == b.size()){
- ans.push_back(i - (b.size() + 1) + 1);
- }
- }
- cout<<ans.size()<<"\n";
- for (auto x: ans){
- cout<<x<<' ';
- }
- //cv(Z);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement