#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 PP be a point on the path. If there is a point QQ directly above PP, and QQ belongs to at least two blocks, then the point QQ 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 W,H,Sx,Sy,Ex,EyW, H, S_x, S_y, E_x, E_y (1WH1051 \leq W \cdot H \leq 10^5, 1Sx,ExW1 \leq S_x, E_x \leq W, 1Sy,EyH1 \leq S_y, E_y \leq H). WW and HH are even integers representing the dimensions of the grid base in meters, integers Sx,SyS_x, S_y denote starting coordinates of the escape path and Ex,EyE_x, E_y denote coordinates of the end.

Each of the next H/2H/2 lines contains W/2W/2 integers, the ii-th integer on jj-th line is the height of the corresponding block Ti,jT_{i,j} in meters (0Ti,j1030 \leq T_{i,j} \leq 10^3).

Each grid block base is a square with dimensions of 2×22 \times 2 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 10410^{-4}.

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.