Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- int n, m;
- cin>>n>>m;
- vector<string> s(n);
- for(auto &e: s) cin>>e;
- vector<vector<int>> vis(n, vector<int> (m, 0));
- string x = "snuke";
- int dx[4] = {1, 0, -1, 0};
- int dy[4] = {0, 1, 0, -1};
- function<void(int, int, int)> DFS = [&](int i, int j, int ind)
- {
- if(s[i][j] != x[ind])
- return;
- vis[i][j] = 1;
- for(int d=0; d<4; d++)
- {
- if(i+dx[d]>=0 && i+dx[d]<n && j+dy[d]>=0 && j+dy[d]<m)
- {
- if(!vis[i+dx[d]][j+dy[d]])
- DFS(i+dx[d], j+dy[d], (ind+1)%5);
- }
- }
- };
- DFS(0, 0, 0);
- if(vis[n-1][m-1]) cout<<"Yes\n";
- else cout<<"No\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment