#P15513. [BalticOI 2003] Table (Day 1)

    ID: 15439 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2003提交答案Special JudgeBalticOI(波罗的海)

[BalticOI 2003] Table (Day 1)

Description

For the given integer MM, build a square table with NN rows and NN columns (2N10)(2 \le N \le 10), filled with decimal digits, with the following restriction: the NN-digit numbers formed by the digits in each table row (from left to right), each table column (from top to bottom) and each main diagonal (from top to bottom) must be multiples of MM, must not start with the digit 00 and must be unique within the table.

For example, a valid table for M=2M = 2 is

234566820\begin{matrix}2&3&4\\5&6&6\\8&2&0\end{matrix}

The following tables are not valid for M=2M = 2:

4\begin{matrix}4\end{matrix}

because N<2N < 2;

2048\begin{matrix}2&0\\4&8\end{matrix}

because the numbers in the last column and on one of the main diagonals start with the digit 00;

234588202\begin{matrix}2&3&4\\5&8&8\\2&0&2\end{matrix}

because the number 482482 is present twice in the table.

It is not always possible to solve this task. For example, the task is unsolvable for M=10M = 10.

Input Format

You are given ten test files TABLEx.IN (1x10)\texttt{TABLE}x\texttt{.IN}\ (1 ≤ x ≤ 10), each containing one value of MM.

Output Format

You must find a valid table for each test case and write it into the corresponding output. The first line must contain NN, the number of rows and columns in the table. The i+1i+1-st line of the output (1iN)(1 ≤ i ≤ N) must contain the elements of the ii-th row of the table as NN digits, separated by spaces.

2
3
2 3 4
5 6 6
8 2 0

Hint

Remark

It is known that there will be at least one solution for each given test input.

Grading

You will score 00 points for a test case if there is no output for this test case or if any of the conditions given above are not met.

Otherwise your score for the test case is calculated from the formula

$$\text{maximum points for the test case} \times \frac{N _ {\text{least among contestants}}}{N _ {\text{yours}}}$$

rounded down to the nearest integer value. Therefore, you should try to find a valid table with the least possible size, within the conditions given above.

Please note that the output for this task is not unique. Also, the grading was relative: the score of each contestant depended on how well other contestants had solved the same test case. For some of the test cases, it is not known whether the tables provided here are indeed the smallest possible. Thus, the output files basically only prove that the required output indeed exists for each given test case.