Source Code
#include <bits/stdc++.h>
#define debug(a) cout << #a << ": " << a << "\n"
#define debugLine() cout << "==============\n"
#define tick() cout << "Tick\n";
#define testCases() int t; cin >> t; while(t--)
#define all(a) a.begin(), a.end()
#define fillWith(a, b) memset(a, b, sizeof(a))
#define INF_32 1e9
#define INF_64 1e18
#define Mod 1000000007
#define endl "\n"
#define goFast() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
using namespace std;

int main()
{
    goFast();
    testCases()
    {
        int n;
        cin >> n;
        string x1;
        string x2;
        cin >> x1;
        cin >> x2;
        vector<pair<int, char>> vec1;
        vector<pair<int, char>> vec2;
        for(int i = 0; i < n; i++)
        {
            if(x1[i] != '.')
                vec1.push_back({i, x1[i]});
        }
        for(int i = 0; i < n; i++)
        {
            if(x2[i] != '.')
                vec2.push_back({i, x2[i]});
        }
        if(vec1.size() != vec2.size())
        {
            cout << "NO" << endl;
            continue;
        }
        bool can = true;
        for(int i = 0; i < vec1.size(); i++)
        {  
            if(vec1[i].second != vec2[i].second)
            {
                can = false;
                break;
            }
            else
            {
                if((vec1[i].second - '0') % 2 == 0)
                {
                    if(vec2[i].first < vec1[i].first)
                    {
                        can = false;
                        break;
                    }
                }
                else
                {
                    if(vec2[i].first > vec1[i].first)
                    {
                        can = false;
                        break;
                    }
                }
            }
        }
        if(can)
            cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
Copy
Moving Digits AhmadShahal
GNU G++17
23 ms
3.5 MB
Accepted