QOJ.ac

QOJ

时间限制: 2 s 内存限制: 1024 MB 总分: 100

#3892. 高效提升

统计

你是 Brussels Architectural Projects Consultancy 的一名员工,负责确保所有建筑设计符合无障碍要求。法律规定,建筑的每一部分都必须能够供轮椅使用者到达,这意味着必须安装电梯。你拿到了公司当前项目的蓝图,需要确定所需的最少电梯数量。

建筑平面图布局在方形网格上,蓝图告知了每个给定方格上的楼层数。你可以在任何方格上安装电梯,电梯会停靠在该方格的所有楼层。轮椅使用者可以使用电梯在楼层之间上下移动,并可以在同一楼层的四个相邻方格之间自由移动。建筑物之间不进行对角连接。

图 E.1 展示了第二个样例输入。设计可以包含多座建筑物;此设计包含三座建筑物。该设计需要两部电梯:一部用于金字塔形状的建筑物,另一部用于高塔。高度为 1 的小型建筑物不需要电梯,因为它只有地面一层。

图 E.1:第二个样例输入的可视化图。

输入格式

输入包含:

  • 一行包含整数 $h$ 和 $w$ ($1 \le h, w \le 500$),表示网格的高度和宽度。
  • $h$ 行,每行包含 $w$ 个整数,其中 $x_{i,j}$ ($0 \le x_{i,j} \le 10^9$),即第 $i$ 行的第 $j$ 个整数,表示网格位置 $(i, j)$ 处的楼层数。

输出格式

输出为了能够到达网格中建筑物的所有部分,你需要建造的最少电梯数量。

样例

样例输入 1

3 3
1 2 3
0 0 4
7 6 5

样例输出 1

1

样例输入 2

6 7
0 0 0 0 0 0 0
0 1 2 3 2 1 0
0 1 2 3 2 1 0
0 0 0 0 0 0 0
0 1 0 5 0 0 0
0 0 0 0 0 0 0

样例输出 2

2

样例输入 3

4 4
1 1 2 1
2 2 1 2
1 2 2 1
2 1 2 2

样例输出 3

4

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.