Advertisement
Guest User

Untitled

a guest
Nov 6th, 2022
6,444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     cin.tie(nullptr)->sync_with_stdio(false);
  6.     int q;
  7.     cin >> q;
  8.     while (q--)
  9.     {
  10.         int n;
  11.         string a, b;
  12.         cin >> n >> a >> b;
  13.         a = '$' + a;
  14.         b = '$' + b;
  15.         bool ok = true;
  16.         for (int i = 1; i <= n; ++i)
  17.         {
  18.             if (a[i] != char('1' - b[i] + '0'))
  19.             {
  20.                 ok = false;
  21.                 break;
  22.             }
  23.         }
  24.         ok = ok || (a == b);
  25.         if (!ok)
  26.         {
  27.             cout << "NO\n";
  28.             continue;
  29.         }
  30.         vector<pair<int, int>> ops;
  31.         if (a[1] != b[1])
  32.         {
  33.             ops.push_back({1, n});
  34.             a = b;
  35.         }
  36.         vector<int> cnt(n + 1);
  37.         for (int i = 1; i <= n; ++i)
  38.         {
  39.             if (a[i] == '1')
  40.             {
  41.                 if (i == 1)
  42.                 {
  43.                     ops.push_back({1, n});
  44.                     ops.push_back({2, n});
  45.                 }
  46.                 else
  47.                 {
  48.                     cnt[i]++;
  49.                     cnt[i - 1]++;
  50.                 }
  51.             }
  52.         }
  53.         for (int i = 1; i <= n; ++i)
  54.         {
  55.             if (cnt[i] % 2 == 1)
  56.             {
  57.                 ops.push_back({1, i});
  58.             }
  59.         }
  60.         cout << "YES\n"
  61.              << (int)ops.size() << '\n';
  62.         for (auto i : ops)
  63.         {
  64.             cout << i.first << ' ' << i.second << '\n';
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement