CEOI '19 Practice P3 - Tower Defense

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 0.6s
Memory limit: 512M

Problem type

You are playing a simple tower defense game.

The game is played on an infinite square grid. At the beginning of the game the entire grid is empty, except for two cells. The cell (x_e, y_e) contains the entrance through which enemy units will be entering the grid. The cell (x_h, y_h) contains your home: a building you are trying to protect from the invaders.

Before the invaders arrive you may build up to 10\,000 turrets. Each turret will occupy one empty cell of the grid.

The invaders can move in four cardinal directions and always follow the shortest path from the entrance to your home. For your master plan, you require that distance to be exactly d.

Input

The first line of input contains two integers: the coordinates x_e and y_e (-10^9 \le x_e, y_e \le 10^9).

The second line of input contains two integers: the coordinates x_h and y_h (-10^9 \le x_h, y_h \le 10^9).

The third line of input contains one integer: the desired distance d (1 \le d \le 2\,000).

The cells (x_e, y_e) and (x_h, y_h) are distinct and their distance on the empty grid is at most 2\,000.

Output

If there is no solution, output a single line with the text impossible.

If there are multiple solutions, you may output any one of them. The first line of output should contain the number t of turrets you want to place (0 \le t \le 10\,000). Each of the following t lines should contain the coordinates of one turret.

All coordinates of all turrets must be between -2 \cdot 10^9 and 2 \cdot 10^9, inclusive.

The checker for this task will also accept solutions that output additional and/or different whitespace between the numbers in the output.

Scoring

Subtask 1 (25 points): (x_e, y_e) = (0, 0) and (x_h, y_h) = (10, 0).

Subtask 2 (28 points): d \le 5.

Subtask 3 (47 points): no additional constraints.

Sample Input 1

10 10
20 20
14

Sample Output 1

impossible

Explanation Of Sample 1

In the first example the current distance from the entrance to your home is already 20. You cannot decrease it to 14 by placing turrets.

Sample Input 2

10 20
10 50
32

Sample Output 2

2
10 47
-1000000003 -5

Explanation Of Sample 2

In the second example the invaders have to go around the turret at (10, 47) which increases the distance between the entrance and your home from 30 to 32. The second turret in this example output is useless and illustrates that you do not have to minimize the number of turrets, and that the turrets can be placed outside the part of the grid that contains the entrance and the exit.

Sample Input 3

0 0
4 0
8

Sample Output 3

6
1 0
1 1
1 2
3 0
3 -1
4 -2

Explanation Of Sample 3

The third example output is shown below, using E for the entrance, H for the home and asterisks for turrets.

.......
..*....
..*....
.E*.*H.
....*..
.....*.
.......

Comments

There are no comments at the moment.