File tree Expand file tree Collapse file tree 1 file changed +57
-3
lines changed Expand file tree Collapse file tree 1 file changed +57
-3
lines changed Original file line number Diff line number Diff line change 1
1
// Authored by : BaaaaaaaaaaarkingDog
2
- // Co-authored by : -
3
- // http://boj.kr/****************
2
+ // Co-authored by : 0silver00
3
+ // http://boj.kr/7daa30318d98480985e402b4e3a14bc1
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
+ #define X first
8
+ #define Y second
9
+ int dx[4 ] = { 1 , 0 , -1 , 0 };
10
+ int dy[4 ] = { 0 , 1 , 0 , -1 };
11
+ int m, n, k;
12
+ int board[102 ][102 ];
13
+ int dist[102 ][102 ];
14
+
7
15
int main (void ){
8
16
ios::sync_with_stdio (0 );
9
17
cin.tie (0 );
10
-
18
+
19
+ cin >> m >> n >> k;
20
+ while (k--) {
21
+ int x1, y1 , x2, y2;
22
+ cin >> x1 >> y1 >> x2 >> y2;
23
+ for (int j = y1 ; j < y2; j++)
24
+ for (int k = x1; k < x2; k++)
25
+ board[j][k] = 1 ;
26
+ }
27
+
28
+ int count = 0 ;
29
+ vector<int > ans;
30
+
31
+ for (int i = 0 ; i < m; i++) {
32
+ for (int j = 0 ; j < n; j++) {
33
+ if (board[i][j] == 1 || dist[i][j] == 1 )
34
+ continue ;
35
+ queue<pair<int , int >> Q;
36
+ dist[i][j] = 1 ;
37
+ Q.push ({ i, j });
38
+ int width = 1 ;
39
+ count++;
40
+ while (!Q.empty ()) {
41
+ auto cur = Q.front ();
42
+ Q.pop ();
43
+ for (int dir = 0 ; dir < 4 ; dir++) {
44
+ int nx = cur.X + dx[dir];
45
+ int ny = cur.Y + dy[dir];
46
+ if (nx < 0 || nx >= m || ny < 0 || ny >= n)
47
+ continue ;
48
+ if (board[nx][ny] == 1 || dist[nx][ny] == 1 )
49
+ continue ;
50
+ Q.push ({ nx, ny });
51
+ dist[nx][ny] = 1 ;
52
+ width++;
53
+ }
54
+ }
55
+ ans.push_back (width);
56
+ }
57
+ }
58
+ sort (ans.begin (), ans.end ());
59
+
60
+ cout << count << ' \n ' ;
61
+ for (int i : ans)
62
+ cout << i << ' ' ;
63
+
64
+ return 0 ;
11
65
}
You can’t perform that action at this time.
0 commit comments