-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13565.cpp
76 lines (72 loc) · 1.07 KB
/
13565.cpp
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
// 13565. 침투
// 2019.05.22
// BFS
#include<iostream>
#include<queue>
using namespace std;
int map[1001][1001];
int visit[1001][1001];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
scanf("%1d",&map[i][j]);
}
}
queue<pair<int, int>> q;
for(int i=0;i<m;i++)
{
if(map[0][i]==0)
{
map[0][i]=2;
q.push({0,i});
}
}
// BFS로 침투
while(!q.empty())
{
int x = q.front().first;
int y = q.front().second;
q.pop();
for(int i = 0; i < 4; i++)
{
int xx = x+dx[i];
int yy = y+dy[i];
if(xx<0 || yy<0 || xx>=n || yy>=m)
{
continue;
}
if(!visit[xx][yy] && map[xx][yy]==0)
{
visit[xx][yy]=1;
map[xx][yy]=2;
q.push({xx,yy});
}
}
}
bool flag = false;
for(int i=0;i<m;i++)
{
if(map[n-1][i]==2)
{
flag=true;
break;
}
}
// 결과 출력
if(flag)
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
return 0;
}