QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100

#16815. 照片编码

统计

你被要求打印一些旧的家庭照片。这些照片非常古老——它们不仅是黑白的,而且像素化得非常严重!实际上,每张照片都可以表示为一个 $n \times n$ 的像素网格,其中每个像素要么是黑色,要么是白色。

在打印每张照片之前,你想买一个完美契合 $n \times n$ 照片的相框。然而,你意识到你并不知道 $n$(照片的尺寸是未知的)!更糟糕的是,你的电脑以一种无法读取的二进制格式存储了这张照片——你唯一能从这张照片中恢复的信息是每个黑色像素到左上角像素的曼哈顿距离列表。位于 $(r_1, c_1)$ 和 $(r_2, c_2)$ 的两个像素之间的曼哈顿距离为 $|r_1 - r_2| + |c_1 - c_2|$。

例如,图 E.1 中 $5 \times 5$ 的照片对应于列表 $[1, 4, 4]$。你注意到可能有多种不同的照片对应于同一个列表。例如,图 E.2 中所示的 $4 \times 4$ 照片也对应于列表 $[1, 4, 4]$。

图 E.1:一张对应于 [1, 4, 4] 的 5 × 5 照片。

图 E.2:一张同样对应于 [1, 4, 4] 的 4 × 4 照片。

考虑到这一点,你想在购买相框时做好准备。给定一个曼哈顿距离列表,你能否确定最小的可能 $n$,使得存在一张与该列表对应的 $n \times n$ 照片?

输入格式

输入的第一行包含一个整数 $m$($1 \le m \le 1000$),表示照片中黑色像素的数量。

接下来的 $m$ 行,每行包含一个介于 $0$ 和 $200$ 之间(含边界)的整数,表示一个黑色像素到照片左上角像素的曼哈顿距离。这些距离按升序给出,且保证对应于一张合法的照片。

输出格式

输出一个整数,即最小的边长 $n$,使得存在一张与输入列表对应的 $n \times n$ 照片。

样例

输入样例 1

3
1
4
4

输出样例 1

4

输入样例 2

8
0
1
3
5
5
5
5
6

输出样例 2

5

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.