-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1926.cpp
74 lines (58 loc) · 1.48 KB
/
1926.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
//1926 그림
#include <iostream>
#include <utility>
#include <queue>
using namespace std;
int arr[500][500];
bool vis[500][500];
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
int num = 0; //그림 수
int max = 0; //최대 그림 넓이
cin >> n >> m;
//input 받기
for(int i =0; i<n; i++)
{
for(int j = 0; j<m; j++)
{
cin >> arr[i][j];
}
}
//bfs
for(int i =0; i<n; i++)
{
for(int j = 0; j<m; j++)
{
if(arr[i][j] == 0 || vis[i][j]==1) //방문했거나, 색칠 안된 칸이면 pass
continue;
num++;
vis[i][j] = 1;
queue<pair<int,int>> q;
q.push(make_pair(i,j));
int area = 0;
while(!q.empty())
{
area++;
pair<int, int> cur = q.front();
q.pop();
for(int k =0; k<4; k++)
{
int nx = cur.first + dx[k];
int ny = cur.second + dy[k];
if(nx < 0 || nx >=n || ny < 0 || ny>=m) continue;
if(vis[nx][ny] ==1 || arr[nx][ny] == 0) continue;
vis[nx][ny] =1;
q.push(make_pair(nx,ny));
}
}
if(area>max) max = area;
}
}
cout << num << '\n';
cout << max << '\n';
return 0;
}