QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 64 MB 満点: 100

#18090. 液体猫

統計

众所周知,当猫进入空容器时,它们会表现出液体的特性。

数学家 Petrov 经常通过他的猫观察到这种现象,甚至进行了一系列实验,建造了不同种类的容器并将猫放进去。结果发现,猫总是选择尽可能低的位置,更准确地说,是使它们身体最高点的高度最小化。如果容器中有多个凹坑,猫会选择最低的那个,但前提是它们能装得下。

一个绝妙的想法出现在 Petrov 的脑海中:事实上,猫可以被用作模拟计算机来解决某些量子优化问题!为了验证他的假设,数学家 Petrov 开发了以下数学模型:

设容器为一个大小为 $n \times m$ 的表格 $T$。某些单元格是墙壁,其余单元格是空的。如果满足以下条件,则猫在容器中的放置是最优的:

  1. 猫占据了若干个空单元格。所有被猫占据的单元格形成一个由 $k$ 个单元格组成的连通形状。如果一个形状中的每个单元格都可以通过相邻的单元格(且所有经过的单元格也都被猫占据)到达其他任何单元格,则称该形状是连通的。
  2. 猫占据的最高单元格的高度 $h$ 应尽可能低。表格的行从 $1$ 到 $n$ 编号,行号越小,高度越高。

不幸的是,数学家 Petrov 不擅长编程。他请求你针对给定的表格 $T$ 和猫的体积 $k$,确定猫占据的最高单元格的高度 $h$。

输入格式

第一行包含整数 $n, m$ 和 $k$ ($1 \le n, m \le 1000, 1 \le k \le 10^6$)。

接下来的 $n$ 行,每行包含 $m$ 个符号,描述了表格 $T$。第 $i$ 行的第 $j$ 个符号对应于 $T$ 中第 $i$ 行和第 $j$ 列的交点处的单元格。“#”表示该单元格是墙壁,“.”表示该单元格是空的。

输出格式

输出猫在任何最优放置方案下,其占据的最高单元格所在的行号。如果猫无法放置在容器中,则输出 “-1”(不含引号)。

样例

输入 1

6 11 7
...........
.......#...
.......#...
#......#...
########...
#######..##

输出 1

4

输入 2

6 11 15
...........
.......#...
.......#...
#......#...
########...
#######..##

输出 2

2

输入 3

5 11 30
..#......##
...........
......#....
......#....
......#....

输出 3

2

说明

每个样例中猫的一种最优放置方案如下:

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.