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$。

範例 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

說明

範例 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

說明

範例 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.