CF8B.Obsession with Robots
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:64MB
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.
全世界都迷上了机器人,为了跟上这一发展步伐,伟大的伯兰程序员德拉德决定打造属于自己的机器人。他为机器人付出了大量心血:教它从一个点到另一个点走最短路径,并记录下它所有的移动过程。然而,如同德拉德编写的许多程序一样,这个机器人也存在一个漏洞——它并不总是走最短路径。幸运的是,机器人对其自身移动过程的记录是完全正确的。现在,德拉德想要弄清楚机器人究竟在何时出现了错误。嘿,倘若德拉德还记得当初测试机器人时所用的场地地图,他便能轻易判断机器人是否朝正确方向行进了。但那张场地地图早已遗失,再也无法找回。因此,他请你帮忙判断:是否存在至少一张地图,使得机器人所记录的路径在该地图上恰好是一条最短路径。
该地图是一张无限大的方格网格,其中每个方格要么为空(即可通过),要么为障碍物。已知机器人绝不会尝试走入障碍物中。请根据机器人所记录的移动序列,判断是否存在至少一张满足如下条件的地图:可以为机器人选定一个起始方格(该起始方格必须为空),使得机器人从该方格出发后,其实际移动轨迹与所记录的轨迹完全一致(即机器人仅在空方格上移动,且不与任何障碍物发生碰撞),并且从起始方格到终点方格的路径长度确为最短路径。
在单次移动中,机器人可移入与其当前所在方格具有公共边(即上下左右相邻)的一个方格(前提是该目标方格中无障碍物)。
输入格式
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.
输入文件的第一行包含机器人运动的记录。该记录是一个非空字符串,由大写拉丁字母 L、R、U 和 D 组成,分别表示向左、向右、向上和向下移动。字符串的长度不超过 100。
输出格式
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
输入解题思路,AI测评打分。不知道怎么写?