COCI '14 Contest 3 #3 Silueta

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 0.16s
Memory limit: 32M

Problem types

The main hero of this task, painter Vincent, spent a great deal of his youth travelling the world. Sights from numerous voyages have often been the inspiration for his, nowadays highly praised, works of art. On one occasion, Vincent found himself in a metropolis full of skyscrapers so he got down to work right away, intoxicated by the marvelous sight. For a number of reasons, incomprehensible to an average programmer, Vincent decided to paint only the silhouettes of the skyscrapers seen before him. Unfortunately, a week after he finished this masterpiece, the painting spontaneously caught fire.

In order to reconstruct the painting, Vincent sought help in all directions; architects provided him with the exact dimensions of the skyscrapers, physicists ignored air resistance, mathematicians mapped everything onto a plane and now it's your turn!

From your perspective, Vincent's skyscrapers are rectangles whose sides are parallel to coordinate axes and with one side that lies on the abscissa. Part of the abscissa on the image should be shown with the characters *, the silhouettes of the skyscrapers with # and fill the rest of the image with .. The left edge of the image must begin with a skyscraper, whereas the right edge of the image must end with a skyscraper. Additionally, in order to verify the results the mathematicians got, output the perimeter of the given silhouette not calculating the sides that lie on the abscissa.

Input Specification

The first line of input contains an integer N (1 \le N \le 10\,000), the number of skyscrapers. Each of the following N lines contains three integers L_i, R_i and H_i (1 \le L_i, R_i, H_i \le 1\,000, 3 \le R_i - L_i \le 1\,000) that describe the position of the i^{th} skyscraper. That skyscraper, in a Cartesian coordinate system, is considered a rectangle with its lower left corner in (L_i, 0) and upper right corner in (R_i, H_i).

Output Specification

The first line of output must contain the perimeter of Vincent's silhouette.

The next h+1 lines, where h+1 is the height of the highest skyscraper, must contain Vincent's drawing as described in the task.

Scoring

In test cases worth 50% of total points, it will hold that 1 \le N \le 100 and 1 \le L_i, R_i, H_i \le 100.

  • If the programme outputs the correct perimeter, but the wrong image, it will get 40% of points for that test case.
  • If the programme outputs the wrong perimeter, but the correct image, it will get 60% of points for that test case.

If you can draw the image, but cannot calculate the perimeter, output a single integer in the first line and then output the image.

Sample Input 1

3
1 5 4
7 11 3
9 13 5

Sample Output 1

28
........####
####....#..#
#..#..###..#
#..#..#....#
#..#..#....#
************

Explanation for Sample Output 1

Blue color denotes the skyscrapers' silhouette (character #), whereas green is the part of abscissa located on Vincent's painting (character *).

Sample Input 2

6
2 8 7
5 13 5
2 18 3
23 26 5
20 31 7
21 30 10

Sample Output 2

61
...................#########.
...................#.......#.
...................#.......#.
######............##.......##
#....#............#.........#
#....######.......#.........#
#.........#.......#.........#
#.........######..#.........#
#..............#..#.........#
#..............#..#.........#
*****************************

Comments

There are no comments at the moment.