#P15563. [CCPC 2025 哈尔滨站] 网格避障
[CCPC 2025 哈尔滨站] 网格避障
Problem Description
Given an grid, the rows are numbered from to , and the columns are numbered from to . Except for the leftmost column and the rightmost column , each column contains at most one obstacle. The leftmost column and the rightmost column are guaranteed to have no obstacles.
You start from any cell in the leftmost column (you may choose the row), and your goal is to reach any cell in the rightmost column (you may choose the row). Suppose you are currently at row , column . In each step, you may choose one of the following three operations:
- Move right: from to .
- Move up: from to .
- Move down: from to .
Moving left is not allowed. At any time, you cannot enter an obstacle cell, and you also cannot move outside the grid.
There are obstacles (after sorting by column index in increasing order, they are numbered from to ). For each obstacle, you must choose either “bypass from above” or “bypass from below”.
If the -th obstacle is at column and row :
- If you choose “bypass from above”, then when you are in column , your row index must always be .
- If you choose “bypass from below”, then when you are in column , your row index must always be .
Choices for different columns are independent, so there are possible plans.
Your task: for each plan, compute the minimum number of steps to go from some row in the leftmost column to some row in the rightmost column while satisfying all constraints of that plan. If there is no feasible path under that plan, output .
Input Format
This problem contains multiple test cases. The first line contains an integer (), representing the number of test cases.
Then each test case is given as follows:
The first line contains two integers (), representing the number of rows and columns of the grid.
The second line contains an integer (), representing the number of obstacles.
The next lines each contain two integers (), meaning there is an obstacle at row , column . It is guaranteed that .
For all test cases, it is guaranteed that . Note that there is no constraint on the sum of over all test cases.
Output Format
For each test case, output one line containing integers, in order, representing the minimum steps for each plan with id from to . Adjacent numbers should be separated by a single space. If a plan has no solution, output .
Plan id description: each plan can be seen as a binary number of length . From low bit to high bit, the bits correspond to obstacles . A bit value of means bypass that obstacle from above, and a bit value of means bypass that obstacle from below.
For example, if , then there are plans, corresponding to:
$$\begin{array}{|c|c|c|} \hline Plan\ ID & Binary\ (low\ bit \to high\ bit) & Bypass\ choice\ (obstacle\ 0,\ obstacle\ 1,\ obstacle\ 2) \\ \hline 0 & 000 & above,\ above,\ above \\ \hline 1 & 100 & below,\ above,\ above \\ \hline 2 & 010 & above,\ below,\ above \\ \hline 3 & 110 & below,\ below,\ above \\ \hline 4 & 001 & above,\ above,\ below \\ \hline 5 & 101 & below,\ above,\ below \\ \hline 6 & 011 & above,\ below,\ below \\ \hline 7 & 111 & below,\ below,\ below \\ \hline \end{array}$$The program should output the minimum number of steps for each plan in increasing order of plan id.
3
3 6
2
3 4
2 5
3 4
1
1 2
3 6
2
3 2
1 5
5 -1 -1 -1
-1 3
-1 -1 5 -1
Hint
Translated by ChatGPT 5