31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

56245. Picture. A child has a lot of coloured rectangular slips of paper and a rectangularboard. The board is divided into unitary squares and it has size of N´´M. Thesizes of slips are such that each slip can be divided into unitary squares.A child spreads slips on the board. Slips are aligned with the squares of the board.Positions of slips on the board are indicated by coordinates of two opposite angles(row and column). Slips are spread on the board in turn. The newly put slip can newlycover squares already covered by other slips.If none of the slips cover the square, it is assumed to be colourless, if one or moreslips cover it, then the colour of square is coincident with colour of the uppermost slip(i. e. this slip was put down the last).It is possible to get from one square of the board to another, if only these squareshave a common edge. Squares of the same colour belong to the same uni-colouredshape, if it is possible to get from one square to another one without crossing squaresof any other colour. Uncovered (colourless) squares cannot make a shape (i.e. we arenot interested in colourless shapes).Task. Write a program to determine how many uni-coloured shapes there are onthe board, which of them is has the largest, and what is the area of that shape.Input. In the first line of the input file there are written three integers. They are thesize of the board N (number of rows) and M (number of columns), 1≤N,M≤1000 andthe number of leaflets L, 1≤L≤1000. Rows are numerated downwards; columns arenumerated from left to right.In the remaining L lines there are data about L leaflets in the order of their placingon the board. Each line contains the colour of the slip (small Latin letter) and thecoordinates of the upper left and of the right bottom corners (row, column) accordingly.There is left one space between numbers or between a number and a letter.None of the slips goes out of the limits of the board, and there are no slips havingarea equal to zero.Output should be written to the first line of the output file. Firstly output the totalnumber (integer) of uni-coloured shapes, then write the colour of the largest unicolouredshape (Latin small letter), the area of the this shape (an integer) and thecoordinates (row and column) of any square, which belongs to that shape. Leave onespace between numbers or between a number and a letter.If several solutions are possible, output any one of them.ExampleInput Output Comments14 14 7r 3 5 10 8g 1 1 9 3j 2 2 4 6r 7 3 11 7g 6 7 8 12m 8 2 13 4r 2 10 6 116 r 27 3 7 Picture below corresponds to thisexample.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!