-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2583.py
More file actions
34 lines (31 loc) · 883 Bytes
/
2583.py
File metadata and controls
34 lines (31 loc) · 883 Bytes
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
m,n,k = map(int,input().split())
s=[[0] * n for i in range(m)]
dx=[0,0,-1,1]
dy=[-1,1,0,0]
cnt=[]
for i in range(k):
x1, y1, x2, y2 = map(int, input().split())
for j in range(y1, y2):
for k in range(x1, x2):
s[j][k] = 1
for i in range(m):
for j in range(n):
if s[i][j] == 0:
count = 1
s[i][j] = 1
queue = [[i, j]]
while queue:
x, y = queue[0][0], queue[0][1]
del queue[0]
for k in range(4):
x1 = x + dx[k]
y1 = y + dy[k]
if 0 <= x1 < m and 0 <= y1 < n and s[x1][y1] == 0:
s[x1][y1] = 1
count += 1
queue.append([x1, y1])
cnt.append(count)
print(len(cnt))
cnt.sort()
for i in cnt:
print(i,end=' ')