CF2215G.Maze

NOI/NOI+/CTSC

通过率:0%

AC君温馨提醒

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

题目描述

There is an $ (n+2) \times (n+2) $ grid, where both coordinates range from $ 0 $ to $ n+1 $ inclusive. The outermost cells of the grid are all obstacle cells.

In addition, there are $ m $ more obstacle cells in the grid. The $ i $ -th obstacle cell is located at $ (x_i, y_i) $ . It is guaranteed that all obstacles (including the outer boundary cells) are 4-connected. That is, you can move between any two obstacle cells by moving up, down, left, or right through other obstacle cells.

Little L is walking in this maze. He cannot step into any obstacle cell at any time. If Little L is at position $ (x, y) $ , he can make the following moves:

  • Move orthogonally to an adjacent cell $ (x+1,y) $ , $ (x-1,y) $ , $ (x,y+1) $ , or $ (x,y-1) $ with a cost of $ 2 $ .
  • Move diagonally to an adjacent cell $ (x+1,y+1) $ , $ (x+1,y-1) $ , $ (x-1,y+1) $ , or $ (x-1,y-1) $ with a cost of $ 3 $ .

There are $ q $ queries. For each query, you are given a starting point and an ending point. You need to find the minimum total cost for Little L to travel from the starting point to the ending point. If it is impossible to reach the ending point, output $ -1 $ .

输入格式

The first line of the input contains three integers $ n $ , $ m $ , and $ q $ ( $ 1 \le n \le 10^5 $ , $ 1 \le m, q \le 3 \cdot 10^5 $ ).

The next $ m $ lines each contain two integers $ x_i $ and $ y_i $ — the coordinates of the $ i $ -th obstacle cell. It is guaranteed that all obstacle coordinates are distinct, and that all obstacles (including the outer boundary cells) are 4-connected.

The next $ q $ lines each contain four integers $ s_x $ , $ s_y $ , $ t_x $ , and $ t_y $ — a query with starting point $ (s_x, s_y) $ and ending point $ (t_x, t_y) $ . It is guaranteed that neither $ (s_x,s_y) $ nor $ (t_x,t_y) $ is an obstacle.

输出格式

For each query, output a single integer — the minimum cost to travel from the starting point to the ending point. Or print $ -1 $ if it is impossible to do so.

输入输出样例

  • 输入#1

    4 4 5
    2 1
    2 2
    3 2
    3 3
    1 1 1 2
    1 1 3 1
    4 1 1 4
    4 4 1 1
    2 3 3 1

    输出#1

    2
    16
    11
    10
    11

说明/提示

For the second query, you can move as follows: $ (1, 1) \to (1, 2) \to (2, 3) \to (3, 4) \to (4, 3) \to (4, 2) \to (3, 1) $ . The total cost is $ 2 + 3 + 3 + 3 + 2 + 3 = 16 $ .

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

首页