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