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>
- #define vec vector
- 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";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- int f(char x){
- return x - 'a' + 1;
- }
- ll mod = 1e9+7, p=37;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string T,S;
- cin>>S>>T;
- int Sn = S.size(), Tn = T.size();
- vector <ll> powP(max(Sn,Tn), 1);
- for (int i = 1; i < powP.size();++i){
- powP[i] = powP[i-1] * p;
- powP[i] %= mod;
- }
- vector <ll> Shp(Sn), Thp(Tn);
- Shp[0] = f(S[0]);
- for (int i=1;i<Sn;++i){
- Shp[i] = Shp[i-1] + f(S[i]) * powP[i];
- Shp[i] %= mod;
- }
- Thp[0] = f(T[0]);
- for (int i=1;i<Tn;++i){
- Thp[i] = Thp[i-1] + f(T[i]) * powP[i];
- Thp[i] %= mod;
- }
- vector <int> ans;
- if (Shp[Tn-1] == Thp[Tn-1]) ans = {0};
- for (int i = 1; i < Sn - Tn + 1; ++i){
- if (Shp[i + Tn - 1] - Shp[i - 1] == Thp[Tn-1] * powP[i] % mod){//%mod - так как мы перемножаем и число может превысить mod
- ans.push_back(i);
- }
- }
- cv(ans);
- }
- /*
- aaaaaaaaaaaaaaaaaaaaaaaaaaaa
- a
- 0 1 2 3 4 5 6 9 11 13 15 18 19 22 24 25
- HERE IS THE MISTAKE!!!
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement