#P8730. [蓝桥杯 2020 国 ABC] 皮亚诺曲线距离
[蓝桥杯 2020 国 ABC] 皮亚诺曲线距离
Problem Description
A Peano curve is a curve on a plane.
The figure below shows the order- Peano curve. It starts from the lower-left corner, passes through every cell in a grid, and finally reaches the upper-right corner.

The figure below shows the order- Peano curve. It passes through every cell in a grid. It is obtained by replacing each cell of the order- curve with an order- curve.

The figure below shows the order- Peano curve. It passes through every cell in a grid. It is obtained by replacing each cell of the order- curve with an order- curve. (Note: in the picture below, the last column is missing one edge due to a drawing error.)

A Peano curve always starts from the lower-left corner and finally reaches the upper-right corner.
We place these cells in a coordinate system. For an order- Peano curve, the lower-left corner is , the upper-right corner is , the lower-right corner is , and the upper-left corner is .
Given the coordinates of two points on an order- Peano curve, what is the distance between these two points if you walk along the Peano curve?
Input Format
The first line contains a positive integer , the order of the Peano curve.
The second line contains two integers , representing the coordinates of the first point.
The third line contains two integers , representing the coordinates of the second point.
Output Format
Output one integer, representing the distance between the given two points.
1
0 0
2 2
8
2
0 2
0 3
13
Hint
For of the test cases, .
For of the test cases, .
For all test cases, , , and . The testdata guarantees that the answer does not exceed .
Lanqiao Cup 2020 National Finals, Group A Problem F (Group B Problem F, Group C Problem H).
Translated by ChatGPT 5