CF8B.Obsession with Robots

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.

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.

被机器人所痴迷

随着科技的发展,全世界的人都对机器人感到痴迷。贝尔兰德的著名程序员Draude决定要制作一个属于自己的机器人。他在努力地训练机器人。他尝试训练机器人走最短的路线从一个地点到另一个地点,并让机器人记录路径。正如许多程序员一样,Draude的程序有Bug。机器人并不每次都走最短的路线。幸运地是,机器人记录的路径是正确的。现在Draude想要寻找出导致机器人没有走最短路径的原因。如果Draude知道整个地图,并且知道机器人一开始的位置,他可以很方便地找出问题所在。不幸地是,地图被Draude丢失了,他再也找不回原来的地图。因此Draude找到你,希望你能判断在是否存在一张地图当机器人记录的路径是最短路的时候。

地图表示的是一个无限平面,平面中每一个格子要么是空的,或者是障碍物。机器人从来不会走到任何一个障碍物上。通过机器人记录的路径找出是否存在至少一个这样的地图,你可以为机器人选择一个起始方格(起始方格应该是空的),使得当机器人从这个方格移动时,其运动与机器人记录的运动一致(机器人不会碰到任何东西,只沿着空的方块移动),并且从起始方块到结束方块的路径是最短的。

在每一次移动中,机器人可以移动到与机器人当前所在的方格具有公共边的方格(上下左右)前提是该方格中没有障碍物)。

感谢Macw提供翻译

输入格式

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.

输入包含一行长度不超过100100的字符串,表示机器人行走的路径。字符串有且仅包含LRUD这四个字符,分别表示机器人的运动方向为左、右、上和下。

输出格式

In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).

如果存在一个符合条件的地图,输出OK,否则输出BUG

输入输出样例

  • 输入#1

    LLUUUR
    

    输出#1

    OK
    
  • 输入#2

    RRUULLDD
    

    输出#2

    BUG
    

说明/提示

请注意,本题的时间限制为2s,是默认时间限制的两倍。本题空间限制为64MB,是默认空间限制的二分之一。

首页