Skyscraper Silhouette
Time limit1sMemory limit32 MB
Rebuild the skyline picture from N ground-based rectangles, mark the border cells, and report the perimeter without the ground side.
- Level
Easy3 of 10
- Topics
- Simulation, Array, Geometry
- Solved
- No attempts yet
Problem
The painter Vincent travelled through a city of skyscrapers and finished a painting of nothing but their silhouette. A week after he finished it, the painting burned. The architects gave him the exact dimensions of the skyscrapers again, so the painting can be reconstructed.
There are skyscrapers. The -th one is a rectangle with sides parallel to the coordinate axes, with its lower left corner at and its upper right corner at . The silhouette is the union of these rectangles.
Let , and . The picture is cells wide, so its left edge is the left side of the leftmost skyscraper and its right edge is the right side of the rightmost skyscraper. The picture has rows for the skyscrapers plus one row for the axis, rows in total. The -th cell from the left covers the interval on the axis, and the -th row from the top covers the interval on the axis. The last row is the axis and is filled with * across the whole width.
Every coordinate is an integer, so each cell above the axis either lies completely inside the silhouette or shares no interior point with it. Call a cell that lies completely inside the silhouette a building cell. If at least one of the eight cells that share a side or a corner with a building cell is not a building cell, write # in that building cell. Write . in every other cell. A cell outside the horizontal range of the picture is not a building cell. Inside that range, the cells on the axis row and below it count as building cells. What is left is the outline of the silhouette.
The value the mathematicians computed has to be checked, so report the perimeter of the silhouette as well. Sides that lie on the axis do not count towards the perimeter.
Input
The first line contains the number of skyscrapers ().
Each of the next lines contains three integers , and describing the -th skyscraper (, ).
Output
On the first line, print the perimeter of the silhouette. Sides lying on the axis are not counted.
On the next lines, print the picture, where is the height of the tallest skyscraper.