Ankit_132

D

Jul 1st, 2023
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  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. int main()
  12. {
  13.     int n, m;
  14.     cin>>n>>m;
  15.  
  16.     vector<string> s(n);
  17.     for(auto &e: s)     cin>>e;
  18.  
  19.     vector<vector<int>> vis(n, vector<int> (m, 0));
  20.  
  21.     string x = "snuke";
  22.  
  23.     int dx[4] = {1, 0, -1, 0};
  24.     int dy[4] = {0, 1, 0, -1};
  25.  
  26.     function<void(int, int, int)> DFS = [&](int i, int j, int ind)
  27.     {
  28.         if(s[i][j] != x[ind])
  29.             return;
  30.  
  31.         vis[i][j] = 1;
  32.  
  33.         for(int d=0; d<4; d++)
  34.         {
  35.             if(i+dx[d]>=0 && i+dx[d]<n && j+dy[d]>=0 && j+dy[d]<m)
  36.             {
  37.                 if(!vis[i+dx[d]][j+dy[d]])
  38.                     DFS(i+dx[d], j+dy[d], (ind+1)%5);
  39.             }
  40.         }
  41.     };
  42.  
  43.     DFS(0, 0, 0);
  44.  
  45.     if(vis[n-1][m-1])       cout<<"Yes\n";
  46.     else                    cout<<"No\n";
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment