Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: Nay-O

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 0.011 second

Submitted On: 2026-02-23 19:04:14

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

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	queue<pair<int,int>> q;
	int m; cin >> m;
	int y,x;
	while(m--){
		int n; cin >> n;
		char arr[2][n+5];
		vector<vector<bool>> vis(2, vector<bool>(n+5,false));
		
		for(int i = 0; i < 2; i++){
			for(int j = 0; j < n; j++){
				cin >> arr[i][j];
				if(arr[i][j]=='S'){
					q.push({i,j});
				}
				else if(arr[i][j]=='T'){
					y=i,x=j;
				}
			}
		}
		
		while(!q.empty()){
			int a = q.front().first;
			int b = q.front().second;
			q.pop();
			if(vis[a][b]) continue;
			vis[a][b]=true;
			for(int i = 0; i < 4; i++){
				int yy= a+dy[i],xx=b+dx[i];
				if(yy<0||xx<0||yy>1||xx>n-1||vis[yy][xx]||arr[yy][xx]=='#') continue;
				q.push({yy,xx});
			}
		}
		if(vis[y][x]) cout << "Yes\n";
		else cout << "No\n";
	}
	
	return 0;
}