#P10988. [蓝桥杯 2023 国 Python A] 走方格
[蓝桥杯 2023 国 Python A] 走方格
Problem Description
Given an by grid. The cell in row and column has coordinates and height . Xiao Lan starts from the top-left corner at , and the destination is the bottom-right corner at .
When Xiao Lan is at row and column , he can move in the following ways:
- If , he can move to , costing second.
- If , he can move to , costing second.
- For any integer , if , he can move to , costing second.
- For any integer , if , he can move to , costing second.
Now the grid is given. How many seconds at minimum does Xiao Lan need to move from to ?
Input Format
The first line contains an integer , indicating the grid size.
The next lines each contain integers, representing the number in each cell.
Output Format
Output one integer representing the answer.
4
0 1 9 3
2 9 3 7
8 4 8 9
9 8 0 7
5
Hint
For of the test cases, .
For of the test cases, .
For all test cases, .
Sample Explanation
The moving order is: $(0, 0)\rightarrow (1, 0)\rightarrow(2, 0)\rightarrow(3, 0)\rightarrow(3, 2)\rightarrow(3, 3)$. The numbers at coordinates are , so he can spend second to move from to .
Translated by ChatGPT 5