#P13660. [CERC 2020] Roof Escape
[CERC 2020] Roof Escape
题目描述
Escaping from the police over city roofs is often tricky and the gangsters have to be trained properly. To keep up with current AI trends in criminality, they are developing a general computerized model of escape paths.
In the model, the city area where the escape happens is modeled as a 3D grid made of rectangular cuboids with square bases forming a 2D grid on flat ground. Each cuboid represents a block of houses. Top face of a cuboid is called a roof. In the model, all distances between adjacent blocks are reduced to 0. The path of escaping gangsters is modeled as a polyline – a sequence of straight horizontal and vertical segments where the end point of one segment is the start point of the next segment. The basic path properties are:
- Each point on the path is on the surface of at least one block.
- No part of the path is in the interior of any block.
- The height of any point on the path is bigger than or equal to the lowest height of roofs of all blocks to which surface the point belongs.
- The path starts and ends in the center of a block roof.
- The sum over the lengths of horizontal segments of the path is minimum possible.
It may happen that two consecutive segments on the path share common points. This stems from the fact that the path models a real behavior of a person moving over physical obstacles. Thus an additional path rule also holds:
- Let be a point on the path. If there is a point directly above , and belongs to at least two blocks, then the point is on the path.
The total length of the escape path should be carefully calculated in the model.
输入格式
The first line of the input contains six positive integers (, , ). and are even integers representing the dimensions of the grid base in meters, integers denote starting coordinates of the escape path and denote coordinates of the end.
Each of the next lines contains integers, the -th integer on -th line is the height of the corresponding block in meters ().
Each grid block base is a square with dimensions of meters in the model.
输出格式
Print the length of the escape path. The difference between the printed length and the exact length must be less than .
8 8 1 7 7 1
2 3 2 0
2 1 1 2
1 2 0 0
0 0 0 1
14.485281374238
提示
The sample input with its solution is shown on the picture above.