codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

8B.md (2275B)


      1 Source: https://codeforces.com/problemset/problem/8/B
      2 
      3 B. Obsession with Robots
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 64 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest.
     22 
     23 The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest.
     24 
     25 In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in.
     26 
     27 Input
     28 
     29 The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
     30 
     31 Output
     32 
     33 In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 LLUUUR
     41 ```
     42 
     43 Output
     44 
     45 ```
     46 OK
     47 ```
     48 
     49 Input
     50 
     51 ```
     52 RRUULLDD
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 BUG
     59 ```