#P1856. [IOI 1998 / USACO5.5] 矩形周长 Picture

[IOI 1998 / USACO5.5] 矩形周长 Picture

Description

Write a program to compute the perimeter.

The 77 rectangles are shown in Figure 1.

The boundary of the union of all rectangles is shown in Figure 2.

All rectangle vertices have integer coordinates.

Input Format

The first line of the input contains an integer NN, the number of rectangles. Each of the next NN lines gives the coordinates of the lower-left corner and the upper-right corner of a rectangle.

Output Format

Output a single positive integer, the perimeter of the union of all rectangles.

7
-15 0 5 10
-5 8 20 25
15 -4 24 14
0 -6 16 4
2 15 10 22
30 10 36 20
34 0 40 16
228

Hint

Constraints

For all testdata, 1N<50001 \le N < 5000, and all coordinate values are in the range 104-10^4 to 10410^4.

Translated by ChatGPT 5