Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Fifaxmb

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 0.008 second

Submitted On: 2026-05-29 20:59:44

#include<bits/stdc++.h>
using namespace std;
#define Fifa67king ios::sync_with_stdio(0);cin.tie(0);
using pii = pair<int,int>;
pii d[] = {{0,-1},{-1,0},{1,0},{0,1}};
int main(){
    Fifa67king;
    int n;cin >> n;
    int ti,tj;
    vector<string> ans(n,"");
    for(int c = 0;c < n;c++){
        int r;cin >> r;
        queue<pii> q;
        vector<vector<char>> v(2,vector<char> (r));
        vector<vector<bool>> vs(2,vector<bool> (r,0));
        for(int i = 0;i < 2;i++){    
            for(int j =0;j < r;j++){
                cin >> v[i][j];
                if(v[i][j] == 'S'){
                    q.push({i,j});
                }
                if(v[i][j] == 'T'){ti = i;tj = j;}
            }
        }
        while(!q.empty()){
            auto [x,y] = q.front();q.pop();
            if(x == ti  && y == tj){
                ans[c] = "Yes";
                break; 
            }
            for(int i = 0;i < 4;i++){
                auto [xx,yy] = d[i];
                xx += x; yy += y;
                if(xx < 0||yy < 0|| xx >= 2 || yy >= r||v[xx][yy] == '#' ||vs[xx][yy]) continue;
                q.push({xx,yy});
                vs[xx][yy] = 1;
            }
        }
        if(ans[c] == "") ans[c] = "No";
    }
    for(auto st : ans){
        cout << st << '\n';
    }
}