P26900 [AtCoder] Grid Gold Movement
省选
题目描述

Problem Description

There is an infinite two-dimensional grid. Snuke is initially at cell $ (0,0) $. There are $ N $ cells with obstacles, and Snuke cannot move to these cells. The $ i $ -th obstacle is located at cell $ (x_i, y_i) $. When Snuke's current position is cell $ (x, y) $, he can move to one of the following $ 6 $ cells in one move:

  • $ (x+1, y+1) $
  • $ (x, y+1) $
  • $ (x-1, y+1) $
  • $ (x+1, y) $
  • $ (x-1, y) $
  • $ (x, y-1) $

Output the minimum number of moves required to reach cell $ (X, Y) $. If it is impossible to reach, output $ -1 $.

Input Format

The input is given from the standard input in the following format:

$ N $ $ X $ $ Y $ $ x_1 $ $ y_1 $ $ : $ $ x_N $ $ y_N $

Output Format

Output the integer specified in the problem.

Sample Input and Output

Sample Input #1

1 2 2
1 1

Sample Output #1

3

Sample Input #2

1 2 2
2 1

Sample Output #2

2

Sample Input #3

5 -2 3
1 1
-1 1
0 1
-2 1
-3 1

Sample Output #3

6

Notes/Hints

Constraints

  • All inputs are integers
  • $1 \leq N \leq 800$
  • $-200 \leq x_i, y_i, X, Y \leq 200$
  • $ (x_i, y_i) $ are distinct. That is, there are no two obstacles in the same cell.
  • There are no obstacles at $ (0, 0) $ or $ (X, Y) $
  • $(X, Y) \neq (0, 0)$

Sample Explanation 1

The following illustrates part of the grid:

..G
.#.
S..

Here, S represents cell $ (0, 0) $, G represents cell $ (X, Y) = (2, 2) $, and # represents a cell with an obstacle. It is possible to reach $ (X, Y) = (2, 2) $ in a minimum of $ 3 $ moves. This can be achieved, for example, by moving $(0, 0) \to (0, 1) \to (1, 2) \to (2, 2)$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
1 2 2 1 1
样例输出
3