Salvens

Untitled

Mar 13th, 2024
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. #define IOS ios::sync_with_stdio(false); cin.tie(0);
  8.  
  9. //#include <ext/pb_ds/assoc_container.hpp>
  10. //using namespace __gnu_pbds;
  11. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  12. //std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
  13.  
  14. const int INF = 1e9 + 100;
  15. const double EPS = 1e-10;
  16. const int MOD = 1e9 + 7;
  17. const int MAXN = 2e5 + 100;
  18.  
  19. string s, t;
  20. int ps[MAXN][26], pt[MAXN][26];
  21. string ans;
  22.  
  23. bool check(int l1, int r1, int l2, int r2) {
  24.     for (int i = 0; i < 26; ++i) {
  25.         if (ps[r1 + 1][i] - ps[l1][i] != pt[r2 + 1][i] - pt[l2][i]) {
  26.             return false;
  27.         }
  28.     }
  29.     return true;
  30. }
  31.  
  32. bool rec(int l1, int r1, int l2, int r2) {
  33.     if (l1 == r1) {
  34.         return s[l1] == t[l2];
  35.     }
  36.  
  37.     int mid1 = (l1 + r1) / 2;
  38.     int mid2 = (l2 + r2) / 2;
  39.     if (check(l1, mid1, l2, mid2) && check(mid1 + 1, r1, mid2 + 1, r2)) {
  40.         if (rec(l1, mid1, l2, mid2) && rec(mid1 + 1, r1, mid2 + 1, r2)) {
  41.             ans += "0 ";
  42.             return true;
  43.         }
  44.     }
  45.     if (check(l1, mid1, mid2 + 1, r2) && check(mid1 + 1, r1, l2, mid2)) {
  46.         if (rec(l1, mid1, mid2 + 1, r2) && rec(mid1 + 1, r1, l2, mid2)) {
  47.             ans += "1 ";
  48.             return true;
  49.         }
  50.     }
  51.     return false;
  52. }
  53.  
  54. inline void solve() {
  55.     cin >> s >> t;
  56.  
  57.     for (int j = 0; j < 26; ++j) {
  58.         ps[0][j] = pt[0][j] = 0;
  59.     }
  60.     ans.clear();
  61.     for (int i = 0; i < s.size(); ++i) {
  62.         for (int j = 0; j < 26; ++j) {
  63.             ps[i + 1][j] = ps[i][j] + (s[i] - 'a' == j);
  64.             pt[i + 1][j] = pt[i][j] + (t[i] - 'a' == j);
  65.         }
  66.     }
  67.  
  68.     if (rec(0, (int)s.size() - 1, 0, (int)t.size() - 1)) {
  69.         cout << "Yes\n";
  70.         cout << ans << '\n';
  71.     } else {
  72.         cout << "No\n";
  73.     }
  74. }
  75.  
  76. int32_t main() {
  77.     IOS;
  78. //    freopen("processing.in", "r", stdin);
  79. //    freopen("processing.out", "w", stdout);
  80.     clock_t tStart = clock();
  81.  
  82.     int tt = 1;
  83.     cin >> tt;
  84.     while (tt --> 0) {
  85.         solve();
  86.     }
  87. //    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment