AtCoder Grand Contest 061
D
Almost Multiplication Table
AtCoder
⌀ 3632
原题
← CE →
翻译中…

Problem Statement

翻译中…

There are positive integers $N, M$, and an $N \times M$ positive integer matrix $A_{i, j}$. For two (strictly) increasing positive integer sequences $X = (X_1, \ldots, X_N)$ and $Y = (Y_1, \ldots, Y_M)$, we define the penalty $D(X, Y)$ as $\max_{1 \leq i \leq N, 1 \leq j \leq M} |X_i Y_j - A_{i, j}|$.

翻译中…

Find two (strictly) increasing positive integer sequences $X$ and $Y$ such that $D(X, Y)$ is the smallest possible.

翻译中…

Constraints

翻译中…
  • $1 \leq N, M \leq 5$
  • $1 \leq A_{i, j} \leq 10^9$ ($1 \leq i \leq N$, $1 \leq j \leq M$)
  • All values in the input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M
A_{1,1} \ldots A_{1,M}
\vdots
A_{N,1} \ldots A_{N,M}

翻译中…

Output

翻译中…

Output your answer in the following format:

翻译中…

D_{min}
X_1 \ldots X_N
Y_1 \ldots Y_M

翻译中…

Here, $D_{min}$ is the smallest possible penalty and the following conditions should be satisfied:

翻译中…
  • $D(X, Y)$ should be equal to $D_{min}$.
  • $X_i < X_{i + 1}$ ($1 \leq i \leq N - 1$).
  • $Y_j < Y_{j + 1}$ ($1 \leq j \leq M - 1$).
  • $1 \leq X_i \leq 2\cdot 10^9$ ($1 \leq i \leq N$).
  • $1 \leq Y_j \leq 2\cdot 10^9$ ($1 \leq j \leq M$).
翻译中…

One can show that there is an optimal solution satisfying the last two conditions.

翻译中…

样例

Input #1
1 1
853922530
Output #1
0
31415
27182
Input #2
3 3
4 4 4
4 4 4
4 4 4
Output #2
5
1 2 3
1 2 3
Input #3
3 4
4674 7356 86312 100327
8737 11831 145034 167690
47432 66105 809393 936462
Output #3
357
129 216 1208
39 55 670 775
题目信息
题号
agc061_d
时间限制
3 s
内存限制
1024 MB

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