-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2583.py
More file actions
60 lines (42 loc) · 1.03 KB
/
Copy path2583.py
File metadata and controls
60 lines (42 loc) · 1.03 KB
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
49
50
51
52
53
54
55
56
57
58
import sys
dir_y = [-1,1,0,0]
dir_x = [0,0,-1,1]
sys.setrecursionlimit(100000)
N, M, K = map(int,sys.stdin.readline().split())
rec = []
for i in range(K):
rec.append(list(map(int,sys.stdin.readline().split())))
board = [[0] * M for i in range(M)]
for k in range(K):
for i in range(N):
for j in range(M):
if rec[k][1] <= i < rec[k][3] and rec[k][0] <= j < rec[k][2]:
board[i][j] = -1
def spread(y,x, idx):
if y < 0 or y >= N or x < 0 or x >= M:
return
if board[y][x] == -1 or board[y][x] == idx:
return
if board[y][x] == 0:
board[y][x] = idx
flag = 1
for i in range(4):
spread(y+dir_y[i],x+dir_x[i],idx)
return flag
idx = 1
for i in range(N):
for j in range(M):
if board[i][j] == 0:
flag = spread(i,j,idx)
if flag == 1:
idx += 1
count = [0] * (idx - 1)
for i in range(N):
for j in range(M):
if board[i][j] > 0:
count[board[i][j]-1] += 1
print(len(count))
if len(count) > 0:
count.sort()
for i in range(len(count)):
print(count[i], end = " ")