ICPC 2018 · Problem E · Getting a Jump on Crime

42nd ICPC · Beijing, China

Statement

Time limit: 2 seconds

Your friend Robin is a superhero. When you first found out about this, you figured “everybody needs a hobby, and this seems more exciting than stamp collecting,” but now you are really thankful that somebody is doing something about the crime in your hometown.

Every night, Robin patrols the city by jumping from roof to roof and watching what goes on below. Naturally, superheroes need to respond to crises immediately, so Robin asked you for help in figuring out how to get around your hometown quickly.

Your hometown is built on a square grid, where each block is w×ww\times w meters. Each block is filled by a single building. The buildings may have different heights (see Figure E.1). To get from one building to another (not necessarily adjacent) building, Robin makes a single jump from the center of the roof of the first building to the center of the roof of the second building. Robin cannot change direction while

Figure E.1: Cross-section of buildings corresponding to the first sample input. Buildings are shown in black, and the jump from the roof at (1,1) to the roof at (4,1) is shown with a green line.

Figure E.1: Cross-section of buildings corresponding to the first sample input. Buildings are shown in black, and the jump from the roof at (1,1)(1,1) to the roof at (4,1)(4,1) is shown with a green line.

Of course, Robin only wants to perform jumps without colliding with any buildings. Such collisions do little damage to a superhero, but building owners tend to get irritated when someone crashes through their windows. You explain the physics to Robin: “All your jumps are done with the same initial velocity vv, which has a horizontal component vdv_{d} towards the destination and vertical component vhv_{h} upwards, so v2v^{2} d+v2d +v^{2} h=v2h = v^{2}. As you travel, your horizontal velocity stays constant (vd(t)=vdv_{d}(t) = v_{d}), but your vertical velocity is affected by gravity (vh(t)=vhtgvh(t) = vh - t \cdot g), where g=9.80665g = 9.80665 m//s22 in your hometown. Naturally, your cape allows you to ignore the effects of air resistance. This allows you to determine your flight path and ...” at which point you notice that Robin has nodded off – less math, more super-heroing!

So it falls to you: given a layout of the city and the location of Robin’s secret hideout, you need to determine which building roofs Robin can reach, and the minimum number of jumps it takes to get to each roof.

Note that if Robin’s jump passes over the corner of a building (where four buildings meet), then the jump needs to be higher than all four adjacent buildings.

ACM-ICPC World Finals 2018 Problem E: Getting a Jump on Crime

Input

The input starts with a line containing six integers dxd_{x}, dyd_{y}, ww, vv, xℓ_{x}, yℓ_{y}. These represent the size dx×dydx\times dy of the city grid (1dx,dy201 \le dx, dy \le 20) in blocks, the width of each building (1w1031 \le w \le 10^{3}) in meters, Robin’s takeoff velocity (1v1031 \le v \le 10^{3}) in meters per second, and the coordinates (x,yℓ_{x}, ℓ_{y}) of Robin’s secret hideout (1xdx1\le ℓx \le dx, 1ydy1\le ℓy \le dy).

The first line is followed by a description of the heights of the buildings in the city grid. The description consists of dyd_{y} lines, each containing dxd_{x} non-negative integers. The jthj^{th} line contains the heights for buildings (1,j),(2,j),...,(dx,j)(1, j),(2, j), . . . ,(d_{x}, j). All heights are given in meters and are at most 10310^{3}.

Output

Display the minimum number of jumps Robin needs to get from the secret hideout to the roof of each building. If there is no way to reach a building’s roof, display X instead of the number of jumps. Display the buildings in the same order as given in the input file, split into dyd_{y} lines, each containing dxd_{x} values.

You may assume that changing the height of any building by up to 10610^{- 6} would not change the answers.

Sample Input 1

4 1 100 55 1 1
10 40 60 10

Sample Output 1

0 1 1 1

Sample Input 2

4 4 100 55 1 1
0 10 20 30
10 20 30 40
20 30 200 50
30 40 50 60

Sample Output 2

0 1 1 2
1 1 1 2
1 1 X 2
2 2 2 3

ACM-ICPC World Finals 2018 Problem E: Getting a Jump on Crime

No official solution in the source collection.