Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: singtoppy

Problemset: Croissant Beyond Peaks

Language: cpp

Time: 0.008 second

Submitted On: 2026-02-07 13:34:19

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

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

	int t;
	cin >> t;

	while(t--) {
		int n, sx, sy;
		cin >> n;

		vector<vector<char>> v(2, vector<char>(n));
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < n; j++) {
				cin >> v[i][j];
				
				if(v[i][j] == 'S') {
					sx = j;
					sy = i;
				}
			}
		}

		vector<vector<bool>> vis(2, vector<bool>(n, false));
		queue<pair<int, int>> q;
		q.push({sy, sx});

		bool ok = false;
		const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
		while(!q.empty()) {
			auto [y, x] = q.front();
			q.pop();

			if(v[y][x] == 'T') {
				ok = true;

				break;
			}

			if(vis[y][x]) {
				continue;
			}

			vis[y][x] = true;

			for(const auto& d : dir) {
				int nx = x + d[1], ny = y + d[0];

				if(nx < n && nx >= 0 && ny < 2 && ny >= 0 && !vis[ny][nx] && v[ny][nx] != '#') {
					q.push({ny, nx});
				}
			}
		}

		if(ok) {
			cout << "Yes" << '\n';
		}
		else {
			cout << "No" << '\n';
		}
	}

	return 0;
}