https://www.acmicpc.net/problem/2583
m,n,k = map(int,input().split())
data = [[0]*n for _ in range(m)]
dx = [-1,1,0,0]
dy = [0,0,-1,1]
for _ in range(k):
a1,a2,b1,b2 = map(int,input().split())
for j in range(a1,b1):
for k in range(a2,b2):
data[k][j] = 1
def dfs(x,y):
count = 1
q = [(x,y)]
data[x][y] = 1
while q:
x,y = q.pop()
for i in range(4):
nx,ny = x+dx[i],y+dy[i]
if 0<=nx<m and 0<=ny<n and data[nx][ny]==0:
data[nx][ny] = 1
q.append((nx,ny))
count += 1
return count
result = 0
number = []
for i in range(m):
for j in range(n):
if data[i][j] == 0:
result += 1
c = dfs(i,j)
number.append(c)
print(result)
number.sort()
print(*number)
'알고리즘' 카테고리의 다른 글
백준 2468번 : 안전 영역(python) (0) | 2021.07.26 |
---|---|
백준 10026번 : 적록색약(python) (0) | 2021.07.26 |
백준 2667번 : 단지번호붙이기(python) (0) | 2021.07.26 |
백준 7576번 : 토마토(python) (0) | 2021.07.26 |
백준 1600번 : 말이 되고픈 원숭이(Python) (0) | 2021.06.20 |