-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2583_영역구하기.py
50 lines (41 loc) · 1.14 KB
/
2583_영역구하기.py
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
def find(row, col):
global layout
stack = [[row, col]]
layout[row][col] = 1
space = 1
while stack:
cur = stack.pop()
for i in range(4):
nr = cur[0] + dx[i]
nc = cur[1] + dy[i]
if 0 <= nr < M and 0 <= nc < N and layout[nr][nc] == 0:
stack.append([nr, nc])
layout[nr][nc] = 1
space += 1
return space
M, N, K = map(int, input().split())
layout = [[0 for _ in range(N)] for _ in range(M)]
# 사각형들 배치
for _ in range(K):
coordinates = [int(i) for i in input().split()]
bottom_left = [M-coordinates[1]-1, coordinates[0]]
top_right = [M-coordinates[3], coordinates[2]-1]
for r in range(top_right[0], bottom_left[0]+1):
for c in range(bottom_left[1], top_right[1]+1):
layout[r][c] += 1
areas = 0
spaces = []
# 영역탐색
# 위, 오, 아, 왼
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
for r in range(M):
for c in range(N):
if layout[r][c] == 0:
areas += 1
spaces.append(find(r, c))
spaces.sort()
print(areas)
for space in spaces:
print(space, end=' ')
print()