Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define IOS ios::sync_with_stdio(false); cin.tie(0);
- //#include <ext/pb_ds/assoc_container.hpp>
- //using namespace __gnu_pbds;
- //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- //std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
- const int INF = 1e18 + 100;
- const double EPS = 1e-10;
- const int MOD = 1e9 + 7;
- const int MAXN = 2e5 + 10;
- string s, t;
- array<int, MAXN> ps, pt;
- string ans;
- bool rec(int l1, int r1, int l2, int r2) {
- if (l1 == r1) {
- return s[l1] == t[l2];
- }
- int mid1 = (l1 + r1) / 2;
- int mid2 = (l2 + r2) / 2;
- if (ps[mid1 + 1] - ps[l1] == pt[mid2 + 1] - pt[l2] && ps[r1 + 1] - ps[mid1 + 1] == pt[r2 + 1] - pt[mid2 + 1]) {
- if (rec(l1, mid1, l2, mid2) && rec(mid1 + 1, r1, mid2 + 1, r2)) {
- ans += "0 ";
- return true;
- }
- }
- if (ps[mid1 + 1] - ps[l1] == pt[r2 + 1] - pt[mid2 + 1] && ps[r1 + 1] - ps[mid1 + 1] == pt[mid2 + 1] - pt[l2]) {
- if (rec(l1, mid1, mid2 + 1, r2) && rec(mid1 + 1, r1, l2, mid2)) {
- ans += "1 ";
- return true;
- }
- }
- return false;
- }
- inline void solve() {
- cin >> s >> t;
- for (int i = 0; i < s.size(); ++i) {
- ps[i + 1] = ps[i] + s[i];
- pt[i + 1] = pt[i] + t[i];
- }
- if (rec(0, (int)s.size() - 1, 0, (int)t.size() - 1)) {
- cout << "Yes\n";
- cout << ans << '\n';
- } else {
- cout << "No\n";
- }
- }
- int32_t main() {
- IOS;
- // freopen("half.in", "r", stdin);
- freopen("output.txt", "w", stdout);
- clock_t tStart = clock();
- int tt = 1;
- cin >> tt;
- while (tt --> 0) {
- solve();
- }
- // cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment