挨家挨户推销员之旅(电梯)AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)Note: This problem has almost the same setting as Problem G. The differences in the problem statements are shown in red bold.
注意:本题的设定与问题 G 几乎相同。题面中的差异以红色粗体显示。AI (CI翻译)
There is an underground apartment represented by a grid with $H$ rows and $W$ columns. The cell at the $i$-th row from the top and the $j$-th column from the left is denoted as cell $(i,j)$.
有一个地下公寓,可以用一个 $H$ 行 $W$ 列的网格表示。从上往下数第 $i$ 行、从左往右数第 $j$ 列的单元格记为 $(i,j)$。AI (CI翻译)
The entrance to the underground apartment is at cell $(1,1)$.
地下公寓的入口位于单元格 $(1,1)$。AI (CI翻译)
The underground apartment has $N$ doors. The $k$-th door is located at cell $(A_k, B_k)$.
地下公寓中有 $N$ 扇门。第 $k$ 扇门位于单元格 $(A_k, B_k)$。AI (CI翻译)
Inside the underground apartment, a salesman can perform the following two types of moves any number of times, in any order:
在地下公寓内,推销员可以以任意顺序、任意次数执行以下两种移动:AI (CI翻译)
- He can walk to a horizontally adjacent cell (left or right) from his current cell. The cost of this move is
$1$. - If his current cell is in column
$1$or column$W$, he can move to a vertically adjacent cell (up or down) by elevator. The cost of this move is$\mathbf{0}$.
- 他可以从当前单元格向左或向右移动到水平相邻的单元格。该移动的费用为
$1$。 - 如果当前单元格位于第
$1$列或第$W$列,他可以通过电梯向上或向下移动到垂直相邻的单元格。该移动的费用为$\mathbf{0}$。
His goal is to start from cell $(1,1)$, repeat moves, visit all $N$ cells with doors at least once, and then arrive at cell $(1,1)$.
他的目标是从单元格 $(1,1)$ 出发,通过重复移动至少访问所有有门的 $N$ 个单元格,最后回到单元格 $(1,1)$。AI (CI翻译)
Find the minimum total cost needed to achieve his goal.
求完成目标所需的最小总费用。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq H \leq 10^9$$2 \leq W \leq 10^9$$1 \leq N \leq 3 \times 10^5$$1 \leq A_k \leq H$$1 \leq B_k \leq W$$(A_1, B_1), \dots, (A_N, B_N)$are distinct.- All input values are integers.
$1 \leq H \leq 10^9$$2 \leq W \leq 10^9$$1 \leq N \leq 3 \times 10^5$$1 \leq A_k \leq H$$1 \leq B_k \leq W$$(A_1, B_1), \dots, (A_N, B_N)$两两不同。- 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
H W
N
A_1 B_1
\vdots
A_N B_N
H W
N
A_1 B_1
\vdots
A_N B_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answer on a single line.
在一行中输出答案。AI (CI翻译)
样例
6 8
7
1 4
2 2
2 7
3 1
6 3
6 4
6 6
18
1000000000 1000000000
2
888888888 600000000
1000000000 700000000
1999999998
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。