Japanese Crossword
Time limit2sMemory limit1024 MB
Given a black and white picture, the task is to print the run lengths of black cells for each row and each column.
- Level
Easy2 of 10
- Topics
- Implementation, Simulation
- Solved
- No attempts yet
Statement
Phineas and Ferb decided to print their own newspaper. It is almost finished, and only one puzzle is left to add at the end. They chose a Japanese crossword.
A Japanese crossword (nonogram) is a puzzle where the goal is to produce a black and white picture of size . The puzzle starts with an empty grid, and some cells must be colored black. To the left of each row, a sequence of numbers is written. These numbers are the lengths of the runs of black cells in that row, listed from left to right. Similarly, above each column, a sequence of numbers is written for the runs of black cells in that column, listed from top to bottom.
Phineas and Ferb picked the picture that the solved puzzle should show. Help them find the number sequences to write beside the rows and above the columns.
Input
The first line contains two integers and , the size of the picture (). The next lines each contain characters describing the picture. A white cell is shown by ., and a black cell is shown by #.
Output
Print lines describing the rows of the crossword from top to bottom. Each line starts with the number of values in that row, followed by the values themselves. Then print lines describing the columns from left to right, in the same format. You may print extra newlines for readability.

