A14026 | The Robot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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)$ . 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 $x$ -coordinate of the current cell decreases by $1$ );
- 'R': one cell to the right (the $x$ -coordinate of the current cell is increased by $1$ );
- 'D': one cell down (the $y$ -coordinate of the current cell decreases by $1$ );
- 'U': one cell up (the $y$ -coordinate of the current cell is increased by $1$ ).
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)$ . Of course, an obstacle cannot be placed in the starting cell $(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)$ ) that if you put an obstacle there, the robot will return to the cell $(0, 0)$ after the execution of all commands. If there is no solution, then report it.
- 'L': one cell to the left (the $x$ -coordinate of the current cell decreases by $1$ );
- 'R': one cell to the right (the $x$ -coordinate of the current cell is increased by $1$ );
- 'D': one cell down (the $y$ -coordinate of the current cell decreases by $1$ );
- 'U': one cell up (the $y$ -coordinate of the current cell is increased by $1$ ).
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)$ . Of course, an obstacle cannot be placed in the starting cell $(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)$ ) that if you put an obstacle there, the robot will return to the cell $(0, 0)$ after the execution of all commands. If there is no solution, then report it.
输入格式
The first line contains one integer $t$ ( $1 \le t \le 500$ ) — the number of test cases.
Each test case consists of a single line containing $s$ — the sequence of commands, which are uppercase Latin letters 'L', 'R', 'D', 'U' only. The length of $s$ is between $1$ and $5000$ , inclusive. Additional constraint on $s$ : executing this sequence of commands leads the robot to some cell other than $(0, 0)$ , if there are no obstacles.
The sum of lengths of all $s$ in a test doesn't exceed $5000$ .
Each test case consists of a single line containing $s$ — the sequence of commands, which are uppercase Latin letters 'L', 'R', 'D', 'U' only. The length of $s$ is between $1$ and $5000$ , inclusive. Additional constraint on $s$ : executing this sequence of commands leads the robot to some cell other than $(0, 0)$ , if there are no obstacles.
The sum of lengths of all $s$ in a test doesn't exceed $5000$ .
输出格式
For each test case print a single line:
- if there is a solution, print two integers $x$ and $y$ ( $-10^9 \le x,y \le 10^9$ ) such that an obstacle in $(x, y)$ will force the robot to return back to the cell $(0, 0)$ ;
- otherwise, print two zeroes (i. e. 0 0).
If there are multiple answers, you can print any of them.
- if there is a solution, print two integers $x$ and $y$ ( $-10^9 \le x,y \le 10^9$ ) such that an obstacle in $(x, y)$ will force the robot to return back to the cell $(0, 0)$ ;
- otherwise, print two zeroes (i. e. 0 0).
If there are multiple answers, you can print any of them.
输入输出样例
输入 #1
4 L RUUDL LLUU DDDUUUUU
输出 #1
-1 0 1 2 0 0 0 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted