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 pb(x) push_back(x)
- 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";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- ll p =101,mod=1e9+7;
- bool sh=0;
- /*
- 1101
- 1011
- 1100100
- 1001101
- 1110100
- 1001110
- ОШИБКА!!!
- */
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- string s,t;
- cin>>s>>t;
- if (s == t){
- cout<<0;
- exit(0);
- }
- int n = s.size();
- vector <ll> powp(n, 1);
- for (int i = 1; i < n; ++i){
- powp[i] = powp[i - 1] * p % mod;
- }
- vector <ll> sf(n), tf(n);
- sf[0] = s[0] - '0' + 1;
- tf[0] = t[0] - '0' + 1;
- for (int i = 1; i < n; ++i){
- sf[i] = sf[i - 1] + ( s[i] - '0' + 1 ) * powp[i] % mod;
- sf[i] %= mod;
- tf[i] = tf[i - 1] + (t[i] - '0' + 1) * powp[i] % mod;
- tf[i] %= mod;
- }
- if (sh){
- cout<<"sf\n"; cvl(sf);
- cout<<"tf\n"; cvl(tf);
- cout<<"powp\n"; cvl(powp);
- }
- int i = -1, mxi=-1;
- if (sh){
- cout<<"i + 1 = "<<i + 1<<"\n";
- cout<<"powp[n - 1 - (i + 1)] = "<<powp[n - 1 - (i + 1)]<<"\n";
- cout<<"sf[i + 1] * powp[n - 1 - (i + 1)] % mod = "<<sf[i + 1] * powp[n - 1 - (i + 1)] % mod<<"\n";
- cout<<"T\n";
- cout<<"n - 1 - (i + 1) = "<<n - 1 - (i + 1)<<"\n";
- cout<<"tf[ n - 1 - (i + 1)] = "<<tf[ n - 1 - (i + 1)]<<"\n";
- }
- while (i+1 < n-1){
- if (i + 1 < n - 1 && sf[i + 1] * powp[n - 1 - (i + 1)] % mod == (tf[n - 1] - tf[n - 1 - (i + 2)] + mod) % mod){
- mxi=i+1;
- }
- if (sh){
- cout<<"i + 1 = "<<i + 1<<"\n";
- cout<<"powp[n - 1 - (i + 1)] = "<<powp[n - 1 - (i + 1)]<<"\n";
- cout<<"sf[i + 1] * powp[n - 1 - (i + 1)] % mod = "<<sf[i + 1] * powp[n - 1 - (i + 1)] % mod<<"\n";
- cout<<"T\n";
- cout<<"n - 1 - (i + 2) = "<<n - 1 - (i + 2)<<"\n";
- cout<<"tf[ n - 1 - (i + 2)] = "<<tf[ n - 1 - (i + 2)]<<"\n";
- }
- i++;
- }
- cout<<n-(mxi+1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement