AtCoder Grand Contest 030
C
Coloring Torus
AtCoder
⌀ 3207
原题
← BD →
翻译中…

Problem Statement

翻译中…

For an $n \times n$ grid, let $(r, c)$ denote the square at the $(r+1)$-th row from the top and the $(c+1)$-th column from the left. A good coloring of this grid using $K$ colors is a coloring that satisfies the following:

翻译中…
  • Each square is painted in one of the $K$ colors.
  • Each of the $K$ colors is used for some squares.
  • Let us number the $K$ colors $1, 2, ..., K$. For any colors $i$ and $j$ ($1 \leq i \leq K, 1 \leq j \leq K$), every square in Color $i$ has the same number of adjacent squares in Color $j$. Here, the squares adjacent to square $(r, c)$ are $((r-1)\; mod\; n, c), ((r+1)\; mod\; n, c), (r, (c-1)\; mod\; n)$ and $(r, (c+1)\; mod\; n)$ (if the same square appears multiple times among these four, the square is counted that number of times).
翻译中…

Given $K$, choose $n$ between $1$ and $500$ (inclusive) freely and construct a good coloring of an $n \times n$ grid using $K$ colors. It can be proved that this is always possible under the constraints of this problem,

翻译中…

Constraints

翻译中…
  • $1 \leq K \leq 1000$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

K

翻译中…

Output

翻译中…

Output should be in the following format:

翻译中…

n
c_{0,0} c_{0,1} ... c_{0,n-1}
c_{1,0} c_{1,1} ... c_{1,n-1}
:
c_{n-1,0} c_{n-1,1} ... c_{n-1,n-1}

翻译中…

$n$ should represent the size of the grid, and $1 \leq n \leq 500$ must hold. $c_{r,c}$ should be an integer such that $1 \leq c_{r,c} \leq K$ and represent the color for the square $(r, c)$.

翻译中…

样例

Input #1
2
Output #1
3
1 1 1
1 1 1
2 2 2
- Every square in Color $1$ has three adjacent squares in Color $1$ and one adjacent square in Color $2$. - Every square in Color $2$ has two adjacent squares in Color $1$ and two adjacent squares in Color $2$. Output such as the following will be judged incorrect:
Input #2
9
Output #2
3
1 2 3
4 5 6
7 8 9
题目信息
题号
agc030_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。