Cut!
InterviewTime limit2sMemory limit1024 MB
Split an n by m grid into connected pieces of exactly k cells each, printing each cell's piece number, or -1 if impossible.
- Level
Easy3 of 10
- Topics
- Implementation, Matrix, Greedy
- Solved
- No attempts yet
Statement
Holding a sheet of graph paper, some of us want to cut it. In this problem you get to act on that urge.
We have only a few requests. First, the sheet may only be cut along the grid lines. Second, each resulting piece of paper must consist of exactly cells of the original sheet.
Input
The first line contains two integers and (), the height and width of the sheet in cells. The second line contains an integer ().
Output
If the sheet cannot be cut in the required way, print -1. Otherwise, print lines with integers each. For each cell, print the number of the piece that contains it. Number the pieces with consecutive positive integers starting from 1.