350C.md (2948B)
1 Source: https://codeforces.com/problemset/problem/350/C 2 3 C. Bombs 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains *n* bombs, the *i*-th bomb is at point with coordinates (*x**i*, *y**i*). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0, 0). Initially, the robot is at point with coordinates (0, 0). Also, let's mark the robot's current position as (*x*, *y*). In order to destroy all the bombs, the robot can perform three types of operations: 22 23 1. Operation has format "1 k dir". To perform the operation robot have to move in direction *dir* *k* (*k* ≥ 1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (*x* + 1, *y*), (*x* - 1, *y*), (*x*, *y* + 1), (*x*, *y* - 1) (corresponding to directions). It is forbidden to move from point (*x*, *y*), if at least one point on the path (besides the destination point) contains a bomb. 24 2. Operation has format "2". To perform the operation robot have to pick a bomb at point (*x*, *y*) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (*x*, *y*) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container. 25 3. Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0, 0). It is forbidden to perform the operation if the container has no bomb. 26 27 Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane. 28 29 Input 30 31 The first line contains a single integer *n* (1 ≤ *n* ≤ 105) — the number of bombs on the coordinate plane. Next *n* lines contain two integers each. The *i*-th line contains numbers (*x**i*, *y**i*) ( - 109 ≤ *x**i*, *y**i* ≤ 109) — the coordinates of the *i*-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0, 0). 32 33 Output 34 35 In a single line print a single integer *k* — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these *k* operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where *k* ≤ 106. 36 37 Examples 38 39 Input 40 41 ``` 42 2 43 1 1 44 -1 -1 45 ``` 46 47 Output 48 49 ``` 50 12 51 1 1 R 52 1 1 U 53 2 54 1 1 L 55 1 1 D 56 3 57 1 1 L 58 1 1 D 59 2 60 1 1 R 61 1 1 U 62 3 63 ``` 64 65 Input 66 67 ``` 68 3 69 5 0 70 0 5 71 1 0 72 ``` 73 74 Output 75 76 ``` 77 12 78 1 1 R 79 2 80 1 1 L 81 3 82 1 5 R 83 2 84 1 5 L 85 3 86 1 5 U 87 2 88 1 5 D 89 3 90 ```