Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <algorithm>
- #include <numeric>
- #include <functional>
- #include <cmath>
- #include <queue>
- #include <stack>
- #include <set>
- #include <map>
- #include <sstream>
- #include <string>
- #define repd(i,a,b) for (int i=(a);i<(b);i++)
- #define rep(i,n) repd(i,0,n)
- #define var auto
- #define mod 1000000007
- #define inf 2147483647
- typedef long long ll;
- using namespace std;
- int inputValue(){
- int a;
- cin >> a;
- return a;
- }
- template <typename T>
- void output(T a, int precision) {
- if(precision > 0){
- cout << fixed << setprecision(precision) << a << "\n";
- }
- else{
- cout << a << "\n";
- }
- }
- // end of template
- bool t[111][3];
- bool isVis[111][3];
- int main() {
- // source code
- int N = inputValue();
- rep(a, N){
- rep(i, 111){
- rep(j, 3){
- t[i][j] = false;
- }
- }
- int row = inputValue();
- int train = inputValue();
- string s[3];
- rep(i, 3){
- cin >> s[i];
- s[i] += "..";
- }
- int start;
- rep(i, 3){
- if (s[i][0] == 's') {
- start = i;
- }
- }
- rep(i, row + 2){
- rep(j, 3){
- t[i][j] = (s[j][i] == '.') ? true : false;
- isVis[i][j] = false;
- }
- }
- priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
- pq.push(make_pair(0, start));
- while (!pq.empty() && pq.top().first < row - 1) {
- var pqt = pq.top();
- pq.pop();
- if (pqt.second >= 1) {
- if (t[pqt.first + 1][pqt.second] && t[pqt.first + 1][pqt.second - 1] && t[pqt.first + 2][pqt.second - 1] && t[pqt.first + 3][pqt.second - 1] && !isVis[pqt.first + 3][pqt.second - 1]) {
- isVis[pqt.first + 3][pqt.second - 1] = true;
- pq.push(make_pair(pqt.first + 3, pqt.second - 1));
- }
- }
- if (pqt.second <= 1) {
- if (t[pqt.first + 1][pqt.second] && t[pqt.first + 1][pqt.second + 1] && t[pqt.first + 2][pqt.second + 1] && t[pqt.first + 3][pqt.second + 1] && !isVis[pqt.first + 3][pqt.second + 1]) {
- isVis[pqt.first + 3][pqt.second + 1] = true;
- pq.push(make_pair(pqt.first + 3, pqt.second + 1));
- }
- }
- if (t[pqt.first + 1][pqt.second] && t[pqt.first + 2][pqt.second] && t[pqt.first + 3][pqt.second] && !isVis[pqt.first + 3][pqt.second]) {
- isVis[pqt.first + 3][pqt.second] = true;
- pq.push(make_pair(pqt.first + 3, pqt.second));
- }
- }
- output((!pq.empty()) ? "YES" : "NO", 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement