Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <vector>
- using namespace std;
- vector<vector<bool> > a;
- vector<vector<bool> > use;
- int dx[6] = {0, 0, 1, 1, -1, -1};
- int dy[6] = {1, -1, 0, -1, 1, 0};
- int n;
- bool check(int x, int y) {
- return x >= 0 && y >= 0 && x < n && y < n;
- }
- bool dfs(int x, int y) {
- if (x == n - 1)
- return true;
- use[x][y] = true;
- for (int i = 0; i < 6; ++i) {
- int new_x = x + dx[i];
- int new_y = y + dy[i];
- if (check(new_x, new_y) && !use[new_x][new_y] && a[new_x][new_y])
- if (dfs(new_x, new_y))
- return true;
- }
- return false;
- }
- int main() {
- cin >> n;
- a.resize(n);
- for (int i = 0; i < n; ++i)
- for (int j = 0; j < n; ++j) {
- char p;
- cin >> p;
- if (p == 'W')
- a[i].push_back(true);
- else
- a[i].push_back(false);
- }
- use = vector<vector<bool> >(n, vector<bool>(n, false));
- for (int i = 0; i < n; ++i) {
- if (!use[0][i] && a[0][i]) {
- if (dfs(0, i)) {
- cout << "YES";
- return 0;
- }
- }
- }
- cout << "NO";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement