#P1948C. Arrow Path
Arrow Path
Description
There is a grid, consisting of $2$ rows and $n$ columns. The rows are numbered from $1$ to $2$ from top to bottom. The columns are numbered from $1$ to $n$ from left to right. Each cell of the grid contains an arrow pointing either to the left or to the right. No arrow points outside the grid.
There is a robot that starts in a cell $(1, 1)$. Every second, the following two actions happen one after another:
- Firstly, the robot moves left, right, down or up (it can't try to go outside the grid, and can't skip a move);
- then it moves along the arrow that is placed in the current cell (the cell it ends up after its move).
Your task is to determine whether the robot can reach the cell $(2, n)$.
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains a single integer ($2 \le n \le 2 \cdot 10^5$).
The second line contains a string consisting of exactly $n$ characters < and/or > — the first row of the grid.
The third line contains a string consisting of exactly $n$ characters < and/or > — the second row of the grid.
Additional constraints on the input:
- $n$ is even;
- there are no arrows pointing outside the grid;
- the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
For each test case, print YES if the robot can reach the cell $(2, n)$; otherwise, print NO.
You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as positive answer.
Input
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first line of each test case contains a single integer ($2 \le n \le 2 \cdot 10^5$).
The second line contains a string consisting of exactly $n$ characters < and/or > — the first row of the grid.
The third line contains a string consisting of exactly $n$ characters < and/or > — the second row of the grid.
Additional constraints on the input:
- $n$ is even;
- there are no arrows pointing outside the grid;
- the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$.
Output
For each test case, print YES if the robot can reach the cell $(2, n)$; otherwise, print NO.
You can print each letter in any case. For example, yes, Yes, YeS will all be recognized as positive answer.
描述
在这里有一个网格,由行列组成。行从上到下编号为到。列从左到右编号为到。网格的每个单元格都包含一个指向左或向右的箭头。没有箭头指向网格外部。
有一个机器人从单元格开始。每秒钟,以下两个动作依次发生:
- 首先,机器人向左、向右、向下或向上移动(不能尝试走出网格,也不能跳过移动);
- 然后沿着当前单元格中放置的箭头移动(它移动后最终停留在的单元格)。
您的任务是确定机器人是否可以到达单元格。
输入
- 第一行包含一个整数()— 测试用例数。
- 每个测试用例的第一行包含一个整数()。
- 第二行包含一个由个字符<和/或>组成的字符串— 网格的第一行。
- 第三行包含一个由个字符<和/或>组成的字符串— 网格的第二行。
输入的附加限制:
- 为偶数;
- 没有箭头指向网格外部;
- 所有测试用例中的总和不超过。
输出
对于每个测试用例,如果机器人可以到达单元格,则打印YES;否则打印NO。
您可以以任何形式打印每个字母。例如,yes、Yes、YeS都将被识别为肯定答案。
4
4
>><<
>>><
2
><
><
4
>>><
>><<
6
>><<><
><>>><
YES
YES
NO
YES
提示
第一个示例
在第一个示例中,可能的一条路径如下:$(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (2, 4)$。
第二个示例
在第二个示例中,可能的一条路径如下:。
第三个示例
在第三个示例中,无法到达单元格。
第四个示例
在第四个示例中,可能的一条路径如下:$(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (2, 5) \rightarrow (2, 6)$。