Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: gay69

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 0.014 second

Submitted On: 2025-12-16 20:39:00

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plpll;

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

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

    ll t;
    cin >> t;
    while (t--) {
        ll n = 2, m;
        cin >> m;
        ll sx = -1, sy = -1;
        char arr[n][m];
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            for (int j = 0; j < m; j++) {
                arr[i][j] = s[j];
                if (s[j] == 'S') {
                    sx = i, sy = j;
                }
            }
        }
        bool flg = false;
        queue<pll> qu;
        bool visited[n][m];
        fill_n(visited[0], n * m, false);
        qu.push({sx, sy});
        while (!qu.empty()) {
            auto [x, y] = qu.front();
            qu.pop();
            if (visited[x][y]) {
                continue;
            }
            if (arr[x][y] == 'T') {
                cout << "Yes\n";
                flg = true;
                break;
            }
            visited[x][y] = true;
            for (int i = 0; i < 4; i++) {
                ll tox = x + dx[i];
                ll toy = y + dy[i];
                if (tox < 0 || toy < 0 || tox > n - 1 || toy > m - 1) {
                    continue;
                }
                if (visited[tox][toy] || arr[tox][toy] == '#') {
                    continue;
                }
                qu.push({tox, toy});
            }
        }
        if (!flg) {
            cout << "No\n";
        }
    }
    return 0;
}