This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub beet-aizu/library
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B #include<bits/stdc++.h> using namespace std; #define call_from_test #include "../../string/rollinghash.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string t,p; cin>>t>>p; using ll = long long; const ll MOD = 1e9+7; const ll B = 1777771; using RH = RollingHash<ll, MOD, B>; RH rt(t),rp(p); for(int i=0;i<(int)t.size()-(int)p.size()+1;i++) if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<"\n"; cout<<flush; return 0; }
#line 1 "test/aoj/ALDS1_14_B.test.cpp" // verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B #include<bits/stdc++.h> using namespace std; #define call_from_test #line 1 "string/rollinghash.cpp" #line 3 "string/rollinghash.cpp" using namespace std; #endif //BEGIN CUT HERE template<typename T,T MOD,T B> struct RollingHash{ using ll = long long; vector<T> hash,po; RollingHash(vector<T> vs){init(vs);} RollingHash(string &s){ vector<T> vs; for(char c:s) vs.emplace_back(c); init(vs); } void init(vector<T> vs){ int n=vs.size(); hash.assign(n+1,0); po.assign(n+1,1); for(int i=0;i<n;i++){ hash[i+1]=((ll)hash[i]*B+vs[i])%MOD; po[i+1]=(ll)po[i]*B%MOD; } } //S[l, r) T find(int l,int r){ T res=(ll)hash[r]+MOD-(ll)hash[l]*po[r-l]%MOD; return res>=MOD?res-MOD:res; } }; //END CUT HERE #ifndef call_from_test //INSERT ABOVE HERE signed main(){ return 0; } #endif #line 8 "test/aoj/ALDS1_14_B.test.cpp" #undef call_from_test signed main(){ cin.tie(0); ios::sync_with_stdio(0); string t,p; cin>>t>>p; using ll = long long; const ll MOD = 1e9+7; const ll B = 1777771; using RH = RollingHash<ll, MOD, B>; RH rt(t),rp(p); for(int i=0;i<(int)t.size()-(int)p.size()+1;i++) if(rt.find(i,i+p.size())==rp.find(0,p.size())) cout<<i<<"\n"; cout<<flush; return 0; }