File tree 1 file changed +40
-0
lines changed
1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 단지번호붙이기
2
+
3
+ N = int (input ())
4
+
5
+ areaMap = []
6
+ visited = [[False ]* N for _ in range (N )]
7
+
8
+ dx = [1 , - 1 , 0 , 0 ]
9
+ dy = [0 , 0 , 1 , - 1 ]
10
+
11
+ answer = [0 ]
12
+
13
+ for _ in range (N ):
14
+ areaMap .append (list (map (int , input ().strip ())))
15
+
16
+
17
+ def dfs (x , y , field ):
18
+ for direction in range (4 ):
19
+ nx = dx [direction ]+ x
20
+ ny = dy [direction ]+ y
21
+ if 0 <= nx < N and 0 <= ny < N and not visited [nx ][ny ]:
22
+ visited [nx ][ny ] = True
23
+ if areaMap [nx ][ny ] == 1 :
24
+ answer [field ] += 1
25
+ dfs (nx , ny , field )
26
+
27
+
28
+ for i in range (N ):
29
+ for j in range (N ):
30
+ if areaMap [i ][j ] == 1 and not visited [i ][j ]:
31
+ visited [i ][j ] = True
32
+ answer [0 ] += 1
33
+ answer .append (1 )
34
+ dfs (i , j , answer [0 ])
35
+
36
+ print (answer [0 ])
37
+ a = sorted (answer [1 :])
38
+
39
+ for i in range (len (a )):
40
+ print (a [i ])
You can’t perform that action at this time.
0 commit comments