UFO Rectangles
InterviewTime limit2sMemory limit512 MB
Find every flattened rectangle frame drawn with X cells in a grid and print the top-left and bottom-right coordinates of each.
- Level
Medium4 of 10
- Topics
- Matrix, Implementation
- Solved
- No attempts yet
Statement
Yandex has a secret department that handles special orders from the governments of different countries. Recently it received a message from a small banana republic that is suffering from an alien invasion.
Crop circles are strange circular formations that sometimes appear in potato or wheat fields, and they may or may not be left by UFOs. In the banana republic, the aliens leave rectangles of flattened banana plants instead.
The photo is divided into cells, and each cell is either intact or flattened. The aliens draw a rectangle by flattening all cells on the frame of an rectangle, where and are both at least . The frames never share cells, and no two frames touch along two or more sides.
XXXXXXXXX XXXXX.... XXXXXXXXXX
X.XXXXX.X X...XXXX. X..XXXXX.X
X.X...X.X X...XX.X. X..X...X.X
X.XXXXX.X X...XX.X. X..X...X.X
X.......X X...XXXX. X..XXXXX.X
XXXXXXXXX XXXXX.... XXXXXXXXXX
OK OK NOT OK
Find all the rectangles the aliens drew so the department can investigate.
Input
The first line contains two integers and (), the dimensions of the photo. Then lines follow, each with characters. Each character is . for an intact cell or X for a flattened cell.
It is guaranteed that the picture corresponds to some set of rectangles that satisfy the conditions above.
Output
On the first line, print an integer (), the number of flattened rectangles in the photo. Then print lines, each with four integers , , , and (, ). These are the row and column numbers of the top-left and bottom-right corners of a rectangle. Rows are numbered 1 to from top to bottom, and columns are numbered 1 to from left to right.
Rectangles may be printed in any order. If several answers are possible, print any one of them.