Construct a traversal of a grid by splitting its cells into a fixed number of non-empty contiguous groups.
Problem
You are given an grid of cells. Your task is to output a traversal of all cells such that the cells are divided into exactly consecutive groups in the order they are visited.
Each group must contain at least one cell, and the groups should be as balanced as possible except that the last group may contain the remaining cells. The goal is to produce any valid traversal that visits every cell exactly once and respects the group boundaries.
A common way to think about the problem is to walk through the grid in a snake-like order and then split the visited sequence into chunks.
Input Format
Input
A single line contains three integers , , and .
Interpretation
- is the number of rows.
- is the number of columns.
- is the number of groups to form while traversing the grid.
Output Format
Output
Print a valid traversal of the grid split into consecutive groups.
The exact formatting depends on the chosen representation, but the output should describe each group and the cells it contains in visitation order.
Constraints
- Every cell must be visited exactly once
- Every group must be non-empty
Example 1
Input
2 3 4
Output
Group 1: (1,1) (1,2) Group 2: (1,3) Group 3: (2,3) Group 4: (2,2) (2,1)
Explanation
One valid snake-like traversal of the 2x3 grid is split into 4 consecutive non-empty groups.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.