#P7886. 「MCOI-06」Gerrymandering
「MCOI-06」Gerrymandering
Description
Given positive integers , is it possible to color an grid such that each color forms exactly one connected component, and every connected component has size ?
If it is possible, construct a valid solution.
Input Format
This problem contains multiple test cases.
The first line contains a positive integer , indicating the number of test cases.
The next lines each contain three positive integers .
Output Format
Output lines. The -th line contains the answer for the -th test case. If it is possible, output YES; otherwise, output NO.
If it is possible, then output more lines, each containing positive integers. Each integer must be no greater than , and cells with the same integer must form a connected component of size exactly .
3
3 3 3
3 3 33
6 6 4
YES
1 1 2
1 2 2
3 3 3
NO
YES
1 1 2 2 3 3
1 2 2 4 4 3
1 5 5 4 6 3
5 5 7 4 6 6
8 7 7 7 9 6
8 8 8 9 9 9
Hint
Explanation for Sample 1
One possible valid output for test case 3:

Constraints
This problem uses bundled tests.
- Subtask 1 (20 pts): .
- Subtask 2 (30 pts): .
- Subtask 3 (50 pts): no special restrictions.
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号