Advertisement
Ankit_132

C

Mar 15th, 2024
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define ff     first
  8. #define ss     second
  9. #define pb     push_back
  10.  
  11.  
  12. int main()
  13. {
  14.     _test
  15.     {
  16.         int n;
  17.         cin>>n;
  18.  
  19.         vector<string> s(2);
  20.         cin>>s[0]>>s[1];
  21.  
  22.         vector<vector<int>> pos(2, vector<int> (n));
  23.  
  24.         pos[0][0] = 1;
  25.  
  26.         queue<pair<int, int>> qp;
  27.  
  28.         qp.push({0, 0});
  29.  
  30.         while(qp.size())
  31.         {
  32.             auto e = qp.front();
  33.             int x = e.ff;
  34.             int y = e.ss;
  35.             qp.pop();
  36.  
  37.             if(x-1>=0)
  38.             {
  39.                 if(s[x-1][y]=='>' && !pos[x-1][y+1])
  40.                 {
  41.                     pos[x-1][y+1] = 1;
  42.                     qp.push({x-1, y+1});
  43.                 }
  44.             }
  45.  
  46.             if(x-1>=0)
  47.             {
  48.                 if(s[x-1][y]=='<' && !pos[x-1][y-1])
  49.                 {
  50.                     pos[x-1][y-1] = 1;
  51.                     qp.push({x-1, y-1});
  52.                 }
  53.             }
  54.  
  55.             if(x+1<=1)
  56.             {
  57.                 if(s[x+1][y]=='>' && !pos[x+1][y+1])
  58.                 {
  59.                     pos[x+1][y+1] = 1;
  60.                     qp.push({x+1, y+1});
  61.                 }
  62.             }
  63.  
  64.             if(x+1<=1)
  65.             {
  66.                 if(s[x+1][y]=='<' && !pos[x+1][y-1])
  67.                 {
  68.                     pos[x+1][y-1] = 1;
  69.                     qp.push({x+1, y-1});
  70.                 }
  71.             }
  72.  
  73.             if(y-1>=0)
  74.             {
  75.                 if(s[x][y-1]=='<' && !pos[x][y-2])
  76.                 {
  77.                     pos[x][y-2] = 1;
  78.                     qp.push({x, y-2});
  79.                 }
  80.             }
  81.  
  82.             if(y+1<n)
  83.             {
  84.                 if(s[x][y+1]=='>' && !pos[x][y+2])
  85.                 {
  86.                     pos[x][y+2] = 1;
  87.                     qp.push({x, y+2});
  88.                 }
  89.             }
  90.         }
  91.  
  92.         if(pos[1][n-1])       cout<<"YES\n";
  93.         else                  cout<<"NO\n";
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement