Submission

Status:

TTTTTTTTTT

Subtask/Task Score:

0/100

Score: 0

User: Nuttykub

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 1.096 second

Submitted On: 2026-10-19 11:04:16

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
    int n;
    cin>>n;
    char arr[2][n];
    for(int i =0;i<2;i++){
        for(int j = 0;j<n;j++) cin>>arr[i][j];
    }
    int startx,starty,endx,endy;
    for(int i =0;i<2;i++){
        for(int j=0;j<n;j++){
            if(arr[i][j] == 'S'){
                startx = i;
                starty = j;
            }
            if(arr[i][j] == 'T'){
                endx= i;
                endy = j;
            }
        }
    }
    bool goal = 1;
    while(arr[startx][starty]!='T'){
        if(arr[0][starty+1]==arr[1][starty+1] and arr[0][starty+1]=='#'){
            goal = 0;
            break;
        }
        if(starty < endy){
            if(arr[startx][starty+1] == '.' or arr[startx][starty+1] == 'T') starty++;
            else if (arr[startx-1][starty] == '.' and startx ==1) startx--;
            else if(arr[startx+1][starty]=='.' and startx==0) startx++;
            else {goal =0;break;}
        }
        else if(starty > endy){
            if(arr[startx][starty-1] == '.' or arr[startx][starty-1]=='T') starty--;
            else if (arr[startx-1][starty] == '.' and startx ==1) startx--;
            else if(arr[startx+1][starty]=='.' and startx==0) startx++; 
            else {goal =0;break;}
        }
        else break;
    }
    if(goal) cout << "Yes";
    else cout <<"No";
    cout << endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t;
    cin>>t;
    while(t--) solve();
}