CF1468K.The Robot

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There is a robot on a checkered field that is endless in all directions. Initially, the robot is located in the cell with coordinates (0,0)(0, 0). He will execute commands which are described by a string of capital Latin letters 'L', 'R', 'D', 'U'. When a command is executed, the robot simply moves in the corresponding direction:

  • 'L': one cell to the left (the xx-coordinate of the current cell decreases by 11);
  • 'R': one cell to the right (the xx-coordinate of the current cell is increased by 11);
  • 'D': one cell down (the yy-coordinate of the current cell decreases by 11);
  • 'U': one cell up (the yy-coordinate of the current cell is increased by 11).

Your task is to put an obstacle in one cell of the field so that after executing the commands, the robot will return to the original cell of its path (0,0)(0, 0). Of course, an obstacle cannot be placed in the starting cell (0,0)(0, 0). It is guaranteed that if the obstacle is not placed, then the robot will not return to the starting cell.

An obstacle affects the movement of the robot in the following way: if it tries to go in a certain direction, and there is an obstacle, then it simply remains in place (the obstacle also remains, that is, it does not disappear).

Find any such cell of the field (other than (0,0)(0, 0)) that if you put an obstacle there, the robot will return to the cell (0,0)(0, 0) after the execution of all commands. If there is no solution, then report it.

有一个机器人位于一个在所有方向上无限延伸的方格场上。初始时,机器人位于坐标为 (0,0)(0, 0) 的格子中。它将执行由大写拉丁字母 'L'、'R'、'D'、'U' 组成的字符串所描述的指令。执行每条指令时,机器人会简单地向对应方向移动一格:

  • 'L':向左移动一格(当前格子的 xx 坐标减 11);
  • 'R':向右移动一格(当前格子的 xx 坐标加 11);
  • 'D':向下移动一格(当前格子的 yy 坐标减 11);
  • 'U':向上移动一格(当前格子的 yy 坐标加 11)。

你的任务是在场上的某个格子中放置一个障碍物,使得机器人执行完全部指令后,能够回到其路径的起始格子 (0,0)(0, 0)。当然,障碍物不能放置在起始格子 (0,0)(0, 0) 中。题目保证:若不放置障碍物,则机器人执行完全部指令后不会回到起始格子。

障碍物对机器人的运动影响如下:若机器人试图朝某一方向移动,而该方向的相邻格子中存在障碍物,则它将停留在原地不动(障碍物也保持不动,即不会消失)。

请找出任意一个满足条件的格子(除 (0,0)(0, 0) 外),使得在该格子放置障碍物后,机器人执行完全部指令将回到格子 (0,0)(0, 0)。若不存在这样的格子,请报告无解。

输入格式

The first line contains one integer tt (1≤t≤5001 \le t \le 500) — the number of test cases.

Each test case consists of a single line containing ss — the sequence of commands, which are uppercase Latin letters 'L', 'R', 'D', 'U' only. The length of ss is between 11 and 50005000, inclusive. Additional constraint on ss: executing this sequence of commands leads the robot to some cell other than (0,0)(0, 0), if there are no obstacles.

The sum of lengths of all ss in a test doesn't exceed 50005000.

第一行包含一个整数 tt(1≤t≤5001 \le t \le 500)—— 表示测试用例的数量。

每个测试用例由一行组成,包含字符串 ss —— 一串命令序列,其中每个命令仅为大写拉丁字母 'L'、'R'、'D' 或 'U'。字符串 ss 的长度在 11 到 50005000 之间(含端点)。关于 ss 的额外约束:若无障碍物,执行该命令序列将使机器人到达除 (0,0)(0, 0) 外的某个格子。

所有测试用例中 ss 的长度总和不超过 50005000。

输出格式

For each test case print a single line:

  • if there is a solution, print two integers xx and yy (−109≤x,y≤109-10^9 \le x,y \le 10^9) such that an obstacle in (x,y)(x, y) will force the robot to return back to the cell (0,0)(0, 0);
  • otherwise, print two zeroes (i. e. 0 0).

If there are multiple answers, you can print any of them.

对每个测试用例,输出一行:

  • 如果存在解,则输出两个整数 xx 和 yy(满足 −109≤x,y≤109-10^9 \le x,y \le 10^9),使得在坐标 (x,y)(x, y) 处放置一个障碍物可迫使机器人返回起点 (0,0)(0, 0);
  • 否则,输出两个零(即 0 0)。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    L
    RUUDL
    LLUU
    DDDUUUUU

    输出#1

    -1 0
    1 2
    0 0
    0 1

输入解题思路,AI测评打分。不知道怎么写?

首页