Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

在 $xy$ 平面上,有 $N$ 个点,编号为 $1, 2, \dots, N$。点 $i$ ($1 \le i \le N$) 的坐标为 $(X_i, Y_i)$。

平面原点处有一个机器人。你的任务是控制机器人按顺序访问所有点 $1, 2, \dots, N$。

机器人有一个字符串变量 $S$,初始为空字符串。你可以使用以下四种操作来移动机器人:

  • 操作 1:将机器人的 $x$ 坐标增加 1,并在 $S$ 的末尾添加字符 X。此操作代价为 1。
  • 操作 2:将机器人的 $y$ 坐标增加 1,并在 $S$ 的末尾添加字符 Y。此操作代价为 1。
  • 操作 3:将机器人的 $x$ 坐标减少 1,并移除 $S$ 的最后一个字符。此操作仅在 $S$ 的最后一个字符为 X 时才能执行。此操作代价为 0。
  • 操作 4:将机器人的 $y$ 坐标减少 1,并移除 $S$ 的最后一个字符。此操作仅在 $S$ 的最后一个字符为 Y 时才能执行。此操作代价为 0。

求机器人按顺序访问所有点 $1, 2, \dots, N$ 所需的最小代价。

输入格式

输入按以下格式给出:

$N$ $X_1$ $Y_1$ $X_2$ $Y_2$ $\vdots$ $X_N$ $Y_N$

  • 所有输入值均为整数。
  • $1 \le N \le 500$
  • $0 \le X_i, Y_i \le 10^9$

输出格式

输出机器人按顺序访问所有点所需的最小代价。

样例

样例 1

2
3 3
1 2

样例 1 输出

6

样例 2

3
2 2
3 3
1 3

样例 2 输出

7

说明

在第一个样例中,通过执行 1 次操作 1、3 次操作 2 和 2 次操作 1,可以到达点 1。然后,通过执行 2 次操作 3 和 1 次操作 4,可以到达点 2。

该操作序列的总代价为执行操作 1 和操作 2 的次数之和,即 6。

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.