A15147 | Robots
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a field divided into $n$ rows and $m$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R).
You can send a command to all robots at the same time. The command can be of one of the four types:
- move up;
- move right;
- move down;
- move left.
When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.
You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?
You can send a command to all robots at the same time. The command can be of one of the four types:
- move up;
- move right;
- move down;
- move left.
When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.
You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?
输入格式
The first line contains one integer $t$ ( $1 \le t \le 5000$ ) — the number of test cases.
Each test case starts with a line containing two integers $n$ and $m$ ( $1 \le n, m \le 5$ ) — the number of rows and the number of columns, respectively. Then $n$ lines follow; each of them contains a string of $m$ characters. Each character is either E (empty cell} or R (robot).
Additional constraint on the input: in each test case, there is at least one robot on the field.
Each test case starts with a line containing two integers $n$ and $m$ ( $1 \le n, m \le 5$ ) — the number of rows and the number of columns, respectively. Then $n$ lines follow; each of them contains a string of $m$ characters. Each character is either E (empty cell} or R (robot).
Additional constraint on the input: in each test case, there is at least one robot on the field.
输出格式
If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.
输入输出样例
输入 #1
6 1 3 ERR 2 2 ER RE 2 2 ER ER 1 1 R 4 3 EEE EEE ERR EER 3 3 EEE EER REE
输出 #1
YES NO YES YES YES NO
Explanations for test cases of the example:
1. in the first test case, it is enough to send a command to move left.
2. in the second test case, if you try to send any command, at least one robot explodes.
3. in the third test case, it is enough to send a command to move left.
4. in the fourth test case, there is already a robot in the upper left corner.
5. in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;
6. in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.
1. in the first test case, it is enough to send a command to move left.
2. in the second test case, if you try to send any command, at least one robot explodes.
3. in the third test case, it is enough to send a command to move left.
4. in the fourth test case, there is already a robot in the upper left corner.
5. in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;
6. in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted