AT_arc219_c.Traveling Door-to-Door Salesman (Elevator)

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Note: This problem has almost the same setting as Problem G. The differences in the problem statements are shown in red bold.

There is an underground apartment represented by a grid with HH rows and WW columns. The cell at the ii-th row from the top and the jj-th column from the left is denoted as cell (i,j)(i,j).

The entrance to the underground apartment is at cell (1,1)(1,1).

The underground apartment has NN doors. The kk-th door is located at cell (Ak,Bk)(A_k, B_k).

Inside the underground apartment, a salesman can perform the following two types of moves any number of times, in any order:

  • He can walk to a horizontally adjacent cell (left or right) from his current cell. The cost of this move is 11.
  • If his current cell is in column 11 or column WW, he can move to a vertically adjacent cell (up or down) by elevator. The cost of this move is 0\mathbf{0}.

His goal is to start from cell (1,1)(1,1), repeat moves, visit all NN cells with doors at least once, and then arrive at cell (1,1)(1,1).

Find the minimum total cost needed to achieve his goal.

注意:本题的设定与问题 G 几乎完全相同。题目描述中的差异以红色粗体标出。

有一个由 HH 行 WW 列组成的网格所表示的地下公寓。从上往下数第 ii 行、从左往右数第 jj 列的格子记为格子 (i,j)(i,j)。

地下公寓的入口位于格子 (1,1)(1,1)。

地下公寓内共有 NN 扇门。第 kk 扇门位于格子 (Ak,Bk)(A_k, B_k)。

在地下公寓内部,一名推销员可以任意次、以任意顺序执行以下两种移动操作:

  • 他可以从当前格子向水平相邻的格子(左或右)行走。该操作的代价为 11。
  • 若他当前所在的格子位于第 11 列或第 WW 列,则他可通过电梯移动至垂直相邻的格子(上或下)。该操作的代价为 0\mathbf{0}。

他的目标是从格子 (1,1)(1,1) 出发,经过若干次移动,至少访问全部 NN 个有门的格子一次,最终返回格子 (1,1)(1,1)。

求达成该目标所需的最小总代价。

输入格式

The input is given from Standard Input in the following format:

HH WW
NN
A1A_1 B1B_1
⋮\vdots
ANA_N BNB_N

输入从标准输入中按以下格式给出:

HH WW
NN
A1A_1 B1B_1
⋮\vdots
ANA_N BNB_N

输出格式

Output the answer on a single line.

在单行中输出答案。

输入输出样例

  • 输入#1

    6 8
    7
    1 4
    2 2
    2 7
    3 1
    6 3
    6 4
    6 6

    输出#1

    18
  • 输入#2

    1000000000 1000000000
    2
    888888888 600000000
    1000000000 700000000

    输出#2

    1999999998

说明/提示

Sample 1 Explanation:
By moving as follows, the goal can be achieved with a total cost of 1818:

  • Start from cell (1,1)(1,1).
  • Move 11 cell down and 11 cell right from cell (1,1)(1,1) to visit cell (2,2)(2,2) (cost 11).
  • Move 11 cell left and 11 cell down from cell (2,2)(2,2) to visit cell (3,1)(3,1) (cost 11).
  • Move 33 cells down and 22 cells right from cell (3,1)(3,1) to visit cell (6,3)(6,3) (cost 22).
  • Move 11 cell right from cell (6,3)(6,3) to visit cell (6,4)(6,4) (cost 11).
  • Move 22 cells right from cell (6,4)(6,4) to visit cell (6,6)(6,6) (cost 22).
  • Move 22 cells right, 44 cells up, and 11 cell left from cell (6,6)(6,6) to visit cell (2,7)(2,7) (cost 33).
  • Move 11 cell right, 11 cell up, and 44 cells left from cell (2,7)(2,7) to visit cell (1,4)(1,4) (cost 55).
  • Move 33 cells left from cell (1,4)(1,4) to arrive at cell (1,1)(1,1) (cost 33).

Constraints

  • 1≤H≤1091 \leq H \leq 10^9
  • 2≤W≤1092 \leq W \leq 10^9
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Ak≤H1 \leq A_k \leq H
  • 1≤Bk≤W1 \leq B_k \leq W
  • (A1,B1),…,(AN,BN)(A_1, B_1), \dots, (A_N, B_N) are distinct.
  • All input values are integers.

样例 1 解释:
通过以下移动方式,可以以总代价 1818 实现目标:

  • 从单元格 (1,1)(1,1) 出发。
  • 从单元格 (1,1)(1,1) 向下移动 11 格、向右移动 11 格,到达单元格 (2,2)(2,2)(代价为 11)。
  • 从单元格 (2,2)(2,2) 向左移动 11 格、向下移动 11 格,到达单元格 (3,1)(3,1)(代价为 11)。
  • 从单元格 (3,1)(3,1) 向下移动 33 格、向右移动 22 格,到达单元格 (6,3)(6,3)(代价为 22)。
  • 从单元格 (6,3)(6,3) 向右移动 11 格,到达单元格 (6,4)(6,4)(代价为 11)。
  • 从单元格 (6,4)(6,4) 向右移动 22 格,到达单元格 (6,6)(6,6)(代价为 22)。
  • 从单元格 (6,6)(6,6) 向右移动 22 格、向上移动 44 格、向左移动 11 格,到达单元格 (2,7)(2,7)(代价为 33)。
  • 从单元格 (2,7)(2,7) 向右移动 11 格、向上移动 11 格、向左移动 44 格,到达单元格 (1,4)(1,4)(代价为 55)。
  • 从单元格 (1,4)(1,4) 向左移动 33 格,回到单元格 (1,1)(1,1)(代价为 33)。

约束条件

  • 1≤H≤1091 \leq H \leq 10^9
  • 2≤W≤1092 \leq W \leq 10^9
  • 1≤N≤3×1051 \leq N \leq 3 \times 10^5
  • 1≤Ak≤H1 \leq A_k \leq H
  • 1≤Bk≤W1 \leq B_k \leq W
  • (A1,B1),…,(AN,BN)(A_1, B_1), \dots, (A_N, B_N) 互不相同。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页