Skip to content

Commit 5870f3d

Browse files
committed
[#14] Feat: Add 단지번호붙이기
1 parent 2dfc272 commit 5870f3d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

2667.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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])

0 commit comments

Comments
 (0)