Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: Fifaxmb
Problemset: Croissant Beyond Peaks
Language: cpp
Time: 0.010 second
Submitted On: 2026-08-11 20:17:59
#include<bits/stdc++.h>
using namespace std;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int q;cin >> q;
while(q--){
int n;cin >> n;
vector<vector<char>> v(2,vector<char>(n));
vector<vector<bool>> vis(2,vector<bool>(n,0));
bool chk = 0;
queue<pair<int,int>> qu;
for(int i = 0;i < 2;i++){
for(int j = 0;j < n;j++){
cin >> v[i][j];
if(v[i][j] == 'S'){
qu.push({i,j});
vis[i][j] = 1;
}
}
}
while(!qu.empty()){
auto [x,y] = qu.front();qu.pop();
if(v[x][y] == 'T'){
chk = 1;
break;
}
for(int d =0;d < 4;d++){
int xx = x + dx[d];
int yy = y + dy[d];
if(xx < 0 || yy < 0 || xx >= 2 || yy > n-1 ||v[xx][yy] == '#' || vis[xx][yy]) continue;
qu.push({xx,yy});
vis[xx][yy] = 1;
}
}
if(chk) cout << "Yes\n";
else cout << "No\n";
}
}