Source Code
#include "bits/stdc++.h"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

void solve(){
    int n;
    cin>>n;
    string a,b;
    cin>>a;
    cin>>b;
    string aa = "",bb="";
    map<char,vector<int>> indA,indB;
    for (int i = 0; i < n; ++i)
    {
        if(a[i] != '.'){
            indA[a[i]].push_back(i);
            aa+=a[i];
        }
        if(b[i] != '.'){
            indB[b[i]].push_back(i);
            bb+=b[i];
        }
    }
    if(aa != bb){
        cout<<"no\n";
        return;
    }
    for(auto i : indA){
        for (int j = 0; j < i.second.size(); ++j)
        {
             if(indB[i.first][j] > i.second[j] and ((i.first - '0') & 1)){
                cout<<"no\n";
                return;
             }
             if(indB[i.first][j] < i.second[j] and (i.first - '0') % 2 == 0){
                cout<<"no\n";
                return;
             }
        }
    }
    cout<<"yes\n";
}

int main(){
    #ifndef ONLINE_JUDGE
     freopen("input.txt", "r", stdin);
     freopen("out.txt", "w",stdout);
    #endif
    FAST;

    int t = 1;
    cin>>t;
    while(t--)
        solve();    
}
Copy
Moving Digits moathhamudah
GNU G++17
56 ms
2.6 MB
Accepted