Time limit
1s
Memory limit
128 MB
There is a sheet of grid paper with height M and width N, where adjacent grid lines are 1 unit apart. When K rectangles are drawn along the grid lines, the cells not covered by the interiors of those rectangles are split into several disconnected regions.
If a rectangle has lower-left corner (x1, y1) and upper-right corner (x2, y2), then every unit cell with x1 <= x < x2 and y1 <= y < y2 is inside that rectangle. Remaining cells belong to the same region when they share an edge.
Given M, N, K, and the coordinates of the K rectangles, write a program that finds how many regions remain outside the rectangles and the area of each region.
The first line contains M, N, and K separated by spaces. M, N, and K are natural numbers not greater than 100.
Each of the next K lines contains four integers: the x- and y-coordinates of the lower-left corner of a rectangle, followed by the x- and y-coordinates of its upper-right corner. The lower-left corner of the grid paper is (0, 0), and the upper-right corner is (N, M). The given rectangles never cover the entire sheet.
Print the number of disconnected regions on the first line.
On the second line, print the areas of all regions in ascending order, separated by spaces.