Universal Cup Judging System

Universal Cup

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓
Estadísticas

在 $xy$ 平面上给定一个简单的 $N$ 边形,其所有边均平行于 $x$ 轴或 $y$ 轴(即一个没有自交且没有孔洞的多边形)。 该多边形的边界上有 $M$ 个演讲地点。 当仅允许沿该多边形的边界移动时,求访问所有演讲地点恰好一次所需的最小总移动距离。 移动的起点和终点可以在多边形的边界上任意选择。

输入格式

第一行包含多边形的顶点数 $N$ 和演讲地点的数量 $M$。 ($4 \le N \le 10^5, 1 \le M \le 10^5$)

第 $(i + 1)$ 行包含简单 $N$ 边形的第 $i$ 个顶点的坐标 $(x_i, y_i)$。 ($1 \le i \le N, |x_i|, |y_i| \le 10^5$) 多边形的边连接第 $i$ 个顶点和第 $(i + 1)$ 个顶点。换句话说,$x_i = x_{i+1}$ 或 $y_i = y_{i+1}$ 成立。(第 $(N + 1)$ 个顶点表示第 $1$ 个顶点。) 没有顶点位于边上。(即不存在角度为 $180$ 度的顶点。)

第 $(j + 1 + N)$ 行包含第 $j$ 个演讲地点的坐标 $(p_j, q_j)$。 ($1 \le j \le M, |p_j|, |q_j| \le 10^5$) 这些点互不相同,且均位于给定多边形的边界上。(包含顶点。)

所有输入值均为整数。

输出格式

输出答案。

样例

输入格式 1

4 3
0 0
3 0
3 2
0 2
0 0
3 0
3 2

输出格式 1

5

说明

在第一个样例中,有三个点位于矩形的顶点上,按 $(0, 0) \to (3, 0) \to (3, 2)$ 的顺序访问它们可得到最短总移动距离,即 $3 + 2 = 5$。

problem_17716_25.png

Figure 1. 样例 1 的多边形和演讲地点

输入格式 2

6 4
0 0
3 0
3 1
2 1
2 2
0 2
3 0
0 2
2 1
1 2

输出格式 2

5
problem_17716_26.png

Figure 2. 样例 2 的多边形和演讲地点

输入格式 3

10 10
-12 -11
-12 9
3 9
3 1
-3 1
-3 -1
8 -1
8 -10
-5 -10
-5 -11
3 1
3 7
7 -1
-3 0
-4 -10
-12 8
-10 -11
-3 9
-12 -10
8 -7

输出格式 3

74
problem_17716_24.png

Figure 3. 样例 3 的多边形和演讲地点

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1525EditorialOpen题解jiangly2026-04-15 16:03:41View

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.