Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: anonymous

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 0.010 second

Submitted On: 2026-11-07 21:53:44

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int q; cin >> q;

    while(q--){
        int n; cin>> n;
        int sx,sy;
        vector<vector<char>> v(2, vector<char>(n));
        for(int i=0;i<2;i++){
            for(int j=0;j<n;j++){
                cin >> v[i][j];

                if(v[i][j] == 'S'){
                    sx = j;
                    sy = i;
                }
            }
        }

        vector<vector<bool>> vis(2, vector<bool>(n, false));
        queue<pair<int, int>> q;
        q.push({sy, sx});

        bool valid = 0;
        const int way[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
        while(!q.empty()){
            auto [y,x] = q.front();
            q.pop();

            if(v[y][x] == 'T'){
                valid = 1;
                break;
            }

            if(vis[y][x]) continue;

            vis[y][x] = 1;

            for(const auto& d : way){
                int tx = x + d[1], ty = y + d[0];

                if(tx < n && tx >= 0 && ty < 2 && ty >= 0 && !vis[ty][tx] && v[ty][tx] != '#'){
                    q.push({ty,tx});
                }
            }
        }

        if(valid) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}