QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#7240. ABBA

Statistics

在这个问题中,我们处理大小为 $h \times w$、由实数组成的表格。我们定义两个表格的加法运算为它们的逐项求和。

对于两个实向量 $\alpha = (\alpha_1, \alpha_2, \dots, \alpha_h)$ 和 $\beta = (\beta_1, \beta_2, \dots, \beta_w)$,其乘法表 $T_{\alpha,\beta}$ 是一个表格,其中第 $i$ 行第 $j$ 列的元素为 $\alpha_i \cdot \beta_j$。

你从一个大小为 $h \times w$、全为零的表格开始。在每一轮中,你可以将一个由任意长度为 $h$ 的向量 $\alpha$ 和长度为 $w$ 的向量 $\beta$ 生成的乘法表加到当前表格上。你的任务是以最少的轮数使当前表格等于目标表格 $G$。你需要执行的最少轮数是多少?

输入格式

第一行包含两个整数 $h$ 和 $w$ ($1 \le h, w \le 200$)。

接下来的 $h$ 行中,第 $i$ 行包含 $w$ 个空格分隔的整数 $a_{i,1}, a_{i,2}, \dots, a_{i,w}$ ($-10^6 \le a_{i,j} \le 10^6$),其中 $a_{i,j}$ 是目标表格 $G$ 中第 $i$ 行第 $j$ 列的值。

输出格式

如果无法得到目标表格 $G$,输出“-1”(不含引号)。否则,输出你必须执行的最少轮数。

样例

样例输入 1

3 5
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15

样例输出 1

1

样例输入 2

3 3
2 0 2
0 2 0
2 0 2

样例输出 2

2

说明

在第一个样例中,表格 $T$ 可以通过 $\alpha = (1, 2, 3)$ 和 $\beta = (1, 2, 3, 4, 5)$ 得到。

在第二个样例中,表格 $T$ 可以表示为 $T_{\alpha_1,\beta_1} = \begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}$(其中 $\alpha_1 = (1, 1, 1)$,$\beta_1 = (1, 1, 1)$)与 $T_{\alpha_2,\beta_2} = \begin{pmatrix} 1 & -1 & 1 \\ -1 & 1 & -1 \\ 1 & -1 & 1 \end{pmatrix}$(其中 $\alpha_2 = (-1, 1, -1)$,$\beta_2 = (-1, 1, -1)$)的和。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.