QOJ.ac

QOJ

时间限制: 10 s 内存限制: 256 MB 总分: 100

#4522. 果园分割 / 分割与出售

统计

Oliver 叔叔打算出售他著名的矮李子果园的很大一部分。他准备将果园分成两部分,卖掉其中一部分,并保留另一部分。

这些树最初种植在规则的行和列中,形成一个行数和列数相同的矩形网格。随着时间的推移,Oliver 移除了许多虚弱或受虫害的树,因此现在也有许多没有树的空方格。

Oliver 决定他将保留果园中恰好一半的树。此外,他还有一些额外的要求,他认为这些要求将确保他保留的那部分果园在未来易于维护:

  • Oliver 要保留的部分应该是一个矩形。
  • 矩形的至少一个角应该与果园的一个角重合。
  • 矩形的面积应该尽可能小。

最初,每棵树都种植在一个面积恰好为一平方米的假想方格的中心。因此,每棵树的位置可以用它所在的方格坐标来描述。果园两部分之间的围栏将沿着方格的边界延伸。

输入格式

输入包含多组测试数据。每组数据的第一行包含两个空格分隔的整数 $M$ ($1 \le M \le 10^9$) 和 $N$ ($1 \le N \le 10^6$)。$M$ 表示果园的边长(单位:米),$N$ 表示果园中树的数量。接下来有 $N$ 行,每行指定一棵树的 $x$ 和 $y$ 坐标,坐标由空格分隔。为简化起见,我们假设坐标是从零开始的,因此果园四个角的方格坐标分别为 $(0, 0), (0, M - 1), (M - 1, M - 1), (M - 1, 0)$。每组测试数据中的所有坐标对 $(x, y)$ 都是唯一的。

输出格式

对于每组测试数据,输出一行,包含一个整数 $A$,表示 Oliver 叔叔保留的那部分果园的最小可能面积(单位:平方米)。如果无法按照 Oliver 的要求划分果园,则输出 “-1”。注意,输出值可能无法用 32 位整数类型存储。

样例

输入 1

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

输出 1

12
-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.