[BOJ 9927] Rectangles

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 128M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

A rectangle whose edges are parallel to the axes can always be defined by the two ends of one of its diagonals. For example, a rectangle can be drawn when the top left $(x_1, y_1)$ and the bottom right $(x_2, y_2)$ coordinates are given.</p>

Given a set of rectangles, we are interested in finding the total area covered by them. For instance, the total area covered by the rectangles below is the area covered within the solid lines. Notice that there is no double counting for overlapping regions.

Write a program that, given a set of rectangles, computes the total area covered by all the rectangles.

입력 형식

The input describes a set of $N$ rectangles where $N$ ranges between 0 to 1000. On the first line is the integer $N$. The remaining lines are the coordinates of the rectangle. In each of these line, the two points $(x_1, y_1)$ and $(x_2, y_2)$ are given as 4 integers $x_1, y_1, x_2, y_2$ separated by one or more blanks. Note that they are NOT necessarily the top-left and bottom-right coordinates. In addition, $x_i$ and $y_i$ take the value between 0 to $32767$.

출력 형식

On the first line of output, your program must write the total area covered by the rectangles. You may assume that the area is at most 32767.

예제 입력

4
20 5 0 15
37 26 14 9
20040 2 20050 18
17 22 33 15

예제 출력

715

Comments

There are no comments at the moment.