atcoder#ABC135E. [ABC135E] Golf
[ABC135E] Golf
Score : points
Problem Statement
Jumbo Takahashi will play golf on an infinite two-dimensional grid.
The ball is initially at the origin , and the goal is a grid point (a point with integer coordinates) . In one stroke, Jumbo Takahashi can perform the following operation:
- Choose a grid point whose Manhattan distance from the current position of the ball is , and send the ball to that point.
The game is finished when the ball reaches the goal, and the score will be the number of strokes so far. Jumbo Takahashi wants to finish the game with the lowest score possible.
Determine if the game can be finished. If the answer is yes, find one way to bring the ball to the goal with the lowest score possible.
What is Manhattan distance?
The Manhattan distance between two points and is defined as .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If the game cannot be finished, print -1
.
If the game can be finished, print one way to bring the ball to the destination with the lowest score possible, in the following format:
Here, is the lowest score possible, and is the position of the ball just after the -th stroke.
11
-1 2
3
7 4
2 10
-1 2
- The Manhattan distance between and is .
- The Manhattan distance between and is .
- The Manhattan distance between and is .
Thus, this play is valid.
Also, there is no way to finish the game with less than three strokes.
4600
52 149
-1
4
9 9
5
1 3
4 2
4 6
6 8
9 9