-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2583(2).cpp
More file actions
48 lines (44 loc) · 955 Bytes
/
2583(2).cpp
File metadata and controls
48 lines (44 loc) · 955 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define MAX 100
using namespace std;
int M, N, K, cnt = 1;
int graph[MAX + 1][MAX + 1];
int dr[4] = { 1, -1, 0, 0 };
int dc[4] = { 0, 0, 1, -1 };
vector<int> ans;
int DFS(int r, int c) {
graph[r][c] = -1;
int cnt = 1;
for (int i = 0; i < 4; i++) {
int nr = r + dr[i], nc = c + dc[i];
if (nr < 0 || nc < 0 || nr >= M || nc >= N) continue;
if (graph[nr][nc] == -1) continue;
cnt += DFS(nr, nc);
}
return cnt;
}
int main() {
cin >> M >> N >> K;
while (K--) {
int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
for (int c = x1; c < x2; c++) {
for (int r = y1; r < y2; r++) {
graph[r][c] = -1;
}
}
}
for (int r = 0; r < M; r++) {
for (int c = 0; c < N; c++) {
if (graph[r][c] != -1) {
ans.push_back(DFS(r, c));
}
}
}
sort(ans.begin(), ans.end());
cout << ans.size() << "\n";
for (int elem : ans) cout << elem << " ";
return 0;
}