#P6945. Robin’s Roof-to-Roof Rescue

    ID: 20152 Type: Default 1000ms 256MiB

Robin’s Roof-to-Roof Rescue

Robin’s Roof-to-Roof Rescue

Your friend Robin is a superhero, patrolling a city built on a square grid of buildings. Each building occupies a w × w meter block and has its own roof height. Every night, Robin leaps from the center of one roof to the center of another using the same initial velocity v. When he jumps, he may choose any take‐off angle so that his horizontal component is vd and his vertical component is vh (with vd2 + vh2 = v2), and gravity (with g = 9.80665 m/s2) decelerates his upward motion. In mid‐flight the horizontal velocity remains constant while the vertical velocity follows vh(t) = vh - g·t.

However, to avoid causing damage (or upsetting the building owners), Robin must make sure his parabolic trajectory does not clip any intervening building. In particular, for a jump from a building with height h₁ to a building with height h₂, the path taken (from center to center) must be strictly above the rooftops of any other buildings that the straight line between the centers passes over. (If the jump passes exactly over a corner where four buildings meet, the jump must be above all four roof heights.)

Your task is to determine, given the grid layout (with each cell’s roof height), the block size w, and the fixed velocity v, the minimum number of jumps required for Robin to reach every building starting from his secret hideout. If a building is unreachable, output -1 for that building.

Note: Robin is allowed to choose the take‐off angle for each jump optimally. For the purpose of this problem, you may assume that verifying a jump’s feasibility can be done by sampling along the straight line between building centers and checking that there exists an angle that produces a trajectory always strictly above any intermediate rooftop.

inputFormat

The first line contains two integers r and c (1 ≤ r, c ≤ 10) representing the number of rows and columns of buildings.

The second line contains two real numbers w and v (w, v > 0) representing the block side length in meters and the fixed initial velocity.

Then follow r lines, each containing c positive integers. The j-th number in the i-th line is the height (in meters) of the building at row i and column j.

The last line contains two integers sr and sc (1 ≤ sr ≤ r, 1 ≤ sc ≤ c) indicating the row and column of Robin's secret hideout (the starting building).

All real numbers in the input will have at most 6 digits after the decimal point.

outputFormat

Output r lines, each containing c space‐separated integers. The j-th number in the i-th line represents the minimum number of jumps required for Robin to reach the building at row i and column j from the starting building. If a building is unreachable, output -1 in its place.

sample

3 3
10 50
10 20 30
20 10 20
30 20 10
2 2
1 1 1

1 0 1 1 1 1

</p>