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";
- }
- bool sh = 0;
- ll mod = 1e9 + 7, p = 101;
- vector <ll> powp(1e4, 1);
- bool f(){
- string s,t;
- cin >> s >> t;
- int sn = s.size(), tn = t.size(), till = 10 * max(sn - 1, tn - 1);
- //док какой степени будем доводить
- if (sn * 2 < tn) {
- if (sh) {
- cout << "BAD SIZE\n";
- }
- return 0;
- }
- vector <ll> sf(sn), resf(sn), tf(tn);
- sf[0] = s[0] - 'a' + 1;
- for (int i = 1; i < sn; ++i) {
- sf[i] = sf[i - 1] + (s[i] - 'a' + 1) * powp[i] % mod;
- sf[i] %= mod;
- }
- resf[sn - 1] = s[sn - 1] - 'a' + 1;
- for (int i = sn - 2; i >= 0; --i) {
- resf[i] = resf[i + 1] + (s[i] - 'a' + 1) * powp[sn - 1 - i] % mod;
- resf[i] %= mod;
- }
- tf[0] = t[0] - 'a' + 1;
- for (int i = 1; i < tn; ++i) {
- tf[i] = tf[i - 1] + (t[i] - 'a' + 1) * powp[i] % mod;
- tf[i] %= mod;
- }
- if (sh) {
- cout << "s t = " << s << ' ' << t << "\n";
- cout << "sn\n";
- cvl(sf);
- cout << "resf\n";
- cvl(resf);
- cout << "tf\n";
- cvl(tf);
- cout << "till = " << till << "\n";
- }
- for (int i = 0; i < sn; ++i) {
- if (sh) {
- cout << "i = " << i << "\n";
- }
- for (int j = i; j <= min(sn - 1, i + tn - 1); ++j) {
- ll del = 0;
- int len = j - i + 1;
- if (i > 0) {
- del = sf[i - 1];
- }
- int left_len = tn - len;
- if (sh) {
- cout << "j = " << j << "\n";
- cout << "len left_len = " << len << ' ' << left_len << "\n";
- }
- if (j - left_len < 0) {
- if (sh) {
- cout << "not enough space\n\n";
- }
- continue;
- }
- ll A = (sf[j] - del + mod) % mod * powp[till - left_len - j] % mod;
- int k = j - left_len;
- ll add = (resf[k] - resf[j] + mod) % mod * powp[till - (sn - 1 - k)] % mod;
- if (sh) {
- cout << "till - left_len - j = " << till - left_len - j << "\n";
- cout << "A = " << A << "\n";
- cout << "k = " << k << "\n";
- cout << "add = " << add << "\n";
- cout << "tf[tn - 1] * powp[till - tn + 1] % mod = " << tf[tn - 1] * powp[till - tn + 1] % mod << "\n";
- }
- A = (A + add) % mod;
- if (A == tf[tn - 1] * powp[till - tn + 1] % mod) {
- if (sh) {
- cout << "GOT IT!\n";
- }
- return 1;
- }
- if (sh) {
- cout << "\n";
- }
- }
- }
- return 0;
- }
- /*
- aaa
- aaaaa
- abcdef
- cdedcb
- abccba
- abc
- aaaaa
- aaaaaa
- */
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- for (int i = 1; i < 1e4; ++i) {
- powp[i] = powp[i - 1] * p % mod;
- }
- int t = 1;
- if (!sh) cin >> t;
- for (int go = 0; go < t; ++ go) {
- if (f()) {
- cout << "YES\n";
- } else cout << "NO\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement