-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13565.cpp
More file actions
80 lines (57 loc) · 1.26 KB
/
13565.cpp
File metadata and controls
80 lines (57 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<cstring>
#include<math.h>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int, int>P;
int M, N;
int arr[1001][1001];
int visited[1001][1001];
int movepos[4][2] = { {0,1},{0,-1},{1,0},{-1,0} };
bool canMove(int x, int y) {
if (x < 0 || x >= M)return false;
if (y < 0 || y >= N)return false;
return true;
}
int main(void)
{
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> N >> M;
for (int i = 0; i < N; i++) {
string temp;
cin >> temp;
for (int j = 0; j < M; j++) {
arr[i][j] = temp[j] - '0';
}
}
queue<P>q;
for (int i = 0; i < M; i++) {
if (arr[0][i] == 0) {
q.push(P(0, i));
visited[0][i] = 1;
}
}
while (!q.empty()) {
P curr = q.front(); q.pop();
int x = curr.second;
int y = curr.first;
if (y == N - 1) {
cout << "YES";
return 0;
}
for (int i = 0; i < 4; i++) {
int gox, goy;
gox = movepos[i][0] + x;
goy = movepos[i][1] + y;
if (canMove(gox, goy) == false)continue;
if (visited[goy][gox] == 1)continue;
if (arr[goy][gox] == 1)continue;
visited[goy][gox] = 1;
q.push(P(goy, gox));
}
}
cout << "NO";
}