This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBOJ2583.java
More file actions
79 lines (65 loc) · 2.01 KB
/
Copy pathBOJ2583.java
File metadata and controls
79 lines (65 loc) · 2.01 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.util.Arrays;
import java.util.Scanner;
public class BOJ2583 {
static int m;
static int n;
static int k;
static int[][] map;
static int[] xDir = new int[]{-1, 0, 1, 0};
static int[] yDir = new int[]{0, 1, 0, -1};
static int answer = 0;
static int[] area;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
n = sc.nextInt();
k = sc.nextInt();
map = new int[m + 2][n + 2];
area = new int[m * n];
Arrays.fill(map[0], 1);
for (int i = 1; i <= m; i++) {
map[i][0] = 1;
map[i][n + 1] = 1;
}
Arrays.fill(map[m + 1], 1);
for (int i = 0; i < k; i++) {
int leftX = sc.nextInt() + 1;
int leftY = sc.nextInt() + 1;
int rightX = sc.nextInt() + 1;
int rightY = sc.nextInt() + 1;
for (int y = leftY; y < rightY; y++) {
for (int x = leftX; x < rightX; x++) {
map[y][x] = 1;
}
}
}
int index = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (dfs(j, i, index)) {
answer++;
index++;
}
}
}
System.out.println(answer);
Arrays.sort(area);
for (int i = 0; i < index; i++) {
System.out.print(area[m * n - index + i] + " ");
}
}
private static boolean dfs(int x, int y, int index) {
boolean canStart = false;
if (map[y][x] == 0) {
canStart = true;
map[y][x] = 1;
area[index]++;
for (int i = 0; i < 4; i++) {
if (map[y + yDir[i]][x + xDir[i]] == 0) {
dfs(x + xDir[i], y + yDir[i], index);
}
}
}
return canStart;
}
}