Advertisement
Korotkodul

CF B debug

Sep 26th, 2022 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool sh = 0;
  51. ll mod = 1e9 + 7, p = 101;
  52. vector <ll> powp(1e4, 1);
  53.  
  54. bool f(){
  55.     string s,t;
  56.     cin >> s >> t;
  57.     int sn = s.size(), tn = t.size(), till = 10 * max(sn - 1, tn - 1);
  58.     //док какой степени будем доводить
  59.     if (sn * 2 < tn) {
  60.         if (sh) {
  61.             cout << "BAD SIZE\n";
  62.         }
  63.         return 0;
  64.     }
  65.     vector <ll> sf(sn), resf(sn), tf(tn);
  66.     sf[0] = s[0] - 'a' + 1;
  67.     for (int i = 1; i < sn; ++i) {
  68.         sf[i] = sf[i - 1] + (s[i] - 'a' + 1) * powp[i] % mod;
  69.         sf[i] %= mod;
  70.     }
  71.     resf[sn - 1] = s[sn - 1] - 'a' + 1;
  72.     for (int i = sn - 2; i >= 0; --i) {
  73.         resf[i] = resf[i + 1] + (s[i] - 'a' + 1) * powp[sn - 1 - i] % mod;
  74.         resf[i] %= mod;
  75.     }
  76.     tf[0] = t[0] - 'a' + 1;
  77.     for (int i = 1; i < tn; ++i) {
  78.         tf[i] = tf[i - 1] + (t[i] - 'a' + 1) * powp[i] % mod;
  79.         tf[i] %= mod;
  80.     }
  81.  
  82.     if (sh) {
  83.         cout << "s t = " << s << ' ' << t << "\n";
  84.         cout << "sn\n";
  85.         cvl(sf);
  86.         cout << "resf\n";
  87.         cvl(resf);
  88.         cout << "tf\n";
  89.         cvl(tf);
  90.         cout << "till = " << till << "\n";
  91.     }
  92.  
  93.     for (int i = 0; i < sn; ++i) {
  94.         if (sh) {
  95.             cout << "i = " << i << "\n";
  96.         }
  97.         for (int j = i; j <= min(sn - 1, i + tn - 1); ++j) {
  98.             ll del = 0;
  99.             int len = j - i + 1;
  100.             if (i > 0) {
  101.                 del = sf[i - 1];
  102.             }
  103.             int left_len = tn - len;
  104.             if (sh) {
  105.                 cout << "j = " << j << "\n";
  106.                 cout << "len left_len = " << len << ' ' << left_len << "\n";
  107.             }
  108.             if (j  - left_len < 0) {
  109.                 if (sh) {
  110.                     cout << "not enough space\n\n";
  111.                 }
  112.                 continue;
  113.             }
  114.             ll A = (sf[j] - del + mod) % mod * powp[till  - left_len - j] % mod;
  115.  
  116.             int k = j - left_len;
  117.             ll add = (resf[k] - resf[j] + mod) % mod * powp[till - (sn - 1 - k)] % mod;
  118.             if (sh) {
  119.                 cout << "till  - left_len - j = " << till  - left_len - j << "\n";
  120.                 cout << "A = " << A << "\n";
  121.                 cout << "k = " << k << "\n";
  122.                 cout << "add = " << add << "\n";
  123.                 cout << "tf[tn - 1] * powp[till - tn + 1] % mod = " << tf[tn - 1] * powp[till - tn + 1] % mod << "\n";
  124.             }
  125.             A = (A + add) % mod;
  126.             if (A == tf[tn - 1] * powp[till - tn + 1] % mod) {
  127.                 if (sh) {
  128.                     cout << "GOT IT!\n";
  129.                 }
  130.                 return 1;
  131.             }
  132.             if (sh) {
  133.                 cout << "\n";
  134.             }
  135.         }
  136.     }
  137.     return 0;
  138. }
  139. /*
  140. aaa
  141. aaaaa
  142.  
  143. abcdef
  144. cdedcb
  145.  
  146.  
  147. abccba
  148. abc
  149.  
  150. aaaaa
  151. aaaaaa
  152. */
  153.  
  154. int main() {
  155.     ios::sync_with_stdio(0);
  156.     cin.tie(0);
  157.     cout.tie(0);
  158.  
  159.     for (int i = 1; i < 1e4; ++i) {
  160.         powp[i] = powp[i - 1] * p % mod;
  161.     }
  162.     int t = 1;
  163.     if (!sh) cin >> t;
  164.     for (int go = 0; go < t; ++ go) {
  165.         if (f()) {
  166.             cout << "YES\n";
  167.         } else cout << "NO\n";
  168.     }
  169. }
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement