QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 100 MB Puntuación total: 100

#6977. T - 覆盖

Estadísticas

如果你玩过俄罗斯方块,你可能知道其中一种形状如下所示:

我们将这种图形称为 T-四格骨牌(T-tetromino);四格骨牌只是由四个单元格组成的连通几何图形的华丽称呼。标记有 $\times$ 的单元格被称为中心格。

Manca 画了一个 $m$ 行 $n$ 列的矩形网格,并在每个单元格中填入一个数字。表格的行编号为 $0$ 到 $m-1$,列编号为 $0$ 到 $n-1$。她还标记了一些单元格为“特殊”单元格(例如,将它们涂成红色)。之后,她要求她的朋友 Nika 在网格上放置 T-四格骨牌,并满足以下条件:

  • T-四格骨牌的数量必须与特殊单元格的数量相同。对于每个 T-四格骨牌,其中心格必须位于某个特殊单元格上。
  • 任意两个 T-四格骨牌不得重叠。
  • 所有 T-四格骨牌必须完全位于网格内。

注意,每个 T-四格骨牌有四种可能的方向($\top, \perp, \vdash, \dashv$)。

如果无法满足这些条件,Nika 应该回答 No;如果可以满足,她必须找到一种放置 T-四格骨牌的方式,使得被 T-四格骨牌覆盖的单元格中的数字之和最大。在这种情况下,她需要告诉 Manca 这个最大和。

请编写一个程序来帮助 Nika 解决这个谜题。

输入格式

每一行包含由单个空格分隔的整数序列。

第一行包含整数 $m$ 和 $n$。接下来的 $m$ 行,每行包含 $n$ 个区间 $[0, 1000]$ 内的整数。第 $i$ 行的第 $j$ 个整数表示网格中第 $i$ 行第 $j$ 列的数字。下一行包含一个整数 $k$。此行后面跟着 $k$ 行,每行包含两个整数 $r_i$ 和 $c_i$($r_i \in \{0, \dots, m-1\}$,$c_i \in \{0, \dots, n-1\}$),分别表示第 $i$ 个特殊单元格的位置(行索引和列索引)。特殊单元格列表中不包含任何重复项。

输出格式

输出被 T-四格骨牌覆盖的单元格中数字的最大可能和,如果不存在有效的放置方式,则输出 No

数据范围

  • $1 \le mn \le 10^6$

子任务

  • 5 分:$k \le 1000$;对于任意两个不同的特殊单元格 $i$ 和 $j$,满足 $|r_i - r_j| > 2$ 或 $|c_i - c_j| > 2$。
  • 10 分:$k \le 1000$;对于任意两个不同的特殊单元格 $i$ 和 $j$,若满足 $|r_i - r_j| \le 2$ 且 $|c_i - c_j| \le 2$,则 $(r_i, c_i)$ 和 $(r_j, c_j)$ 在侧边上相邻,或者更正式地说,以下陈述成立:$(|r_i - r_j| = 1 \text{ 且 } |c_i - c_j| = 0)$ 或 $(|r_i - r_j| = 0 \text{ 且 } |c_i - c_j| = 1)$。
  • 10 分:$k \le 1000$;对于任意两个不同的特殊单元格 $i$ 和 $j$,若满足 $|r_i - r_j| \le 2$ 且 $|c_i - c_j| \le 2$,则 $|r_i - r_j| \le 1$ 且 $|c_i - c_j| \le 1$。
  • 10 分:$k \le 1000$;所有特殊单元格位于同一行。
  • 15 分:$k \le 10$。
  • 20 分:$k \le 1000$。
  • 30 分:无附加限制。

样例

样例输入 1

5 6
7 3 8 1 0 9
4 6 2 5 8 3
1 9 7 3 9 5
2 6 8 4 5 7
3 8 2 7 3 6
3
1 1
2 2
3 4

样例输出 1

67

说明 1

为了达到最大和,Nika 可以按如下方式放置四格骨牌: $\dashv$ 在单元格 $(1, 1)$; $\vdash$ 在单元格 $(2, 2)$; * $\perp$ 在单元格 $(3, 4)$。

样例输入 2

5 6
7 3 8 1 0 9
4 6 2 5 8 3
1 9 7 3 9 5
2 6 8 4 5 7
3 8 2 7 3 6
3
1 1
2 2
3 3

样例输出 2

No

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.