atcoder#ARC142B. [ARC142B] Unbalanced Squares
[ARC142B] Unbalanced Squares
Score : points
Problem Statement
We have an grid. Let denote the square at the -th row from the top and -th column from the left in this grid. Find one way to write an integer on every square to satisfy the conditions below.
- Each integer between and is written exactly once.
- For every pair of integers , the square satisfies the following.- Among the squares horizontally, vertically, or diagonally adjacent to (there are at most eight of them), let and be the number of squares with integers larger than and smaller than that of , respectively. Then, holds.
- Among the squares horizontally, vertically, or diagonally adjacent to (there are at most eight of them), let and be the number of squares with integers larger than and smaller than that of , respectively. Then, holds.
Under the Constraints of this problem, it can be proved that such a way to write integers always exists.
Constraints
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
Print a way to write integers to satisfy the conditions, in the following format:
Here, is the integer to write on the square . If multiple solutions exist, any of them will be accepted.
2
1 2
3 4
This output contains each integer between and exactly once, so the first condition is satisfied. Additionally, among the squares horizontally, vertically, or diagonally adjacent to the square , three squares , , and have integers larger than that of , and none has an integer smaller than that. Thus, for , we have and , so holds. Similarly, it can be verified that also holds for the other squares, so the second condition is satisfied. Therefore, this output is valid.
3
1 2 3
5 4 6
7 8 9