Salvens

Untitled

Mar 13th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 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 = 1e18 + 100;
  15. const double EPS = 1e-10;
  16. const int MOD = 1e9 + 7;
  17. const int MAXN = 2e5 + 10;
  18.  
  19. string s, t;
  20. array<int, MAXN> ps, pt;
  21. string ans;
  22.  
  23. bool rec(int l1, int r1, int l2, int r2) {
  24. if (l1 == r1) {
  25. return s[l1] == t[l2];
  26. }
  27.  
  28. int mid1 = (l1 + r1) / 2;
  29. int mid2 = (l2 + r2) / 2;
  30. if (ps[mid1 + 1] - ps[l1] == pt[mid2 + 1] - pt[l2] && ps[r1 + 1] - ps[mid1 + 1] == pt[r2 + 1] - pt[mid2 + 1]) {
  31. if (rec(l1, mid1, l2, mid2) && rec(mid1 + 1, r1, mid2 + 1, r2)) {
  32. ans += "0 ";
  33. return true;
  34. }
  35. }
  36. if (ps[mid1 + 1] - ps[l1] == pt[r2 + 1] - pt[mid2 + 1] && ps[r1 + 1] - ps[mid1 + 1] == pt[mid2 + 1] - pt[l2]) {
  37. if (rec(l1, mid1, mid2 + 1, r2) && rec(mid1 + 1, r1, l2, mid2)) {
  38. ans += "1 ";
  39. return true;
  40. }
  41. }
  42. return false;
  43. }
  44.  
  45. inline void solve() {
  46. cin >> s >> t;
  47.  
  48. for (int i = 0; i < s.size(); ++i) {
  49. ps[i + 1] = ps[i] + s[i];
  50. pt[i + 1] = pt[i] + t[i];
  51. }
  52.  
  53. if (rec(0, (int)s.size() - 1, 0, (int)t.size() - 1)) {
  54. cout << "Yes\n";
  55. cout << ans << '\n';
  56. } else {
  57. cout << "No\n";
  58. }
  59. }
  60.  
  61. int32_t main() {
  62. IOS;
  63. // freopen("half.in", "r", stdin);
  64. freopen("output.txt", "w", stdout);
  65.  
  66. clock_t tStart = clock();
  67.  
  68. int tt = 1;
  69. cin >> tt;
  70. while (tt --> 0) {
  71. solve();
  72. }
  73. // cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment