CCC '11 J4 - Boring Business


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
C++, Python

Input Specification

The input consists of a sequence of drilling command pairs. A drilling command pair begins with one of four direction indicators ( d for down, u for up, l for left, and r for right) followed by a positive length. There is an additional drilling command indicated by q (quit) followed by any integer, which indicates the program should stop execution. You can assume that the input is such that the drill point will not:

  • rise above the ground, nor
  • be more than \(200\) units below ground, nor
  • be more than \(200\) units to the left of the original starting point, nor
  • be more than \(200\) units to the right of the original starting point

Output Specification

The program should continue to monitor drilling assuming that the well shown in the figure has already been made. As we can see \((-1, -5)\) is the starting position for your program. After each command, the program must output one line with the coordinates of the new position of the drill, and one of the two comments safe , if there has been no intersection with a previous position or DANGER if there has been an intersection with a previous borehole location. After detecting and reporting a self-intersection, your program must stop.

Sample Input 1

l 2
d 2
r 1
q 0

Output for Sample Input 1

-3 -5 safe
-3 -7 safe
-2 -7 safe

Sample Input 2

r 2
d 10
r 4
q 0

Output for Sample Input 2

1 -5 safe
1 -15 DANGER

Comments

There are no comments at the moment.