A12903 | Pipes
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$ .
There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:
 Types of pipes You can turn each of the given pipes $90$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $1$ and $2$ can become each other and types $3, 4, 5, 6$ can become each other).
You want to turn some pipes in a way that the water flow can start at $(1, 0)$ (to the left of the top left pipe), move to the pipe at $(1, 1)$ , flow somehow by connected pipes to the pipe at $(2, n)$ and flow right to $(2, n + 1)$ .
Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:
 Examples of connected pipes Let's describe the problem using some example:
 The first example input And its solution is below:
 The first example answer As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $(1, 2)$ $90$ degrees clockwise, the pipe at $(2, 3)$ $90$ degrees, the pipe at $(1, 6)$ $90$ degrees, the pipe at $(1, 7)$ $180$ degrees and the pipe at $(2, 7)$ $180$ degrees. Then the flow of water can reach $(2, n + 1)$ from $(1, 0)$ .
You have to answer $q$ independent queries.
There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:
 Types of pipes You can turn each of the given pipes $90$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $1$ and $2$ can become each other and types $3, 4, 5, 6$ can become each other).
You want to turn some pipes in a way that the water flow can start at $(1, 0)$ (to the left of the top left pipe), move to the pipe at $(1, 1)$ , flow somehow by connected pipes to the pipe at $(2, n)$ and flow right to $(2, n + 1)$ .
Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:
 Examples of connected pipes Let's describe the problem using some example:
 The first example input And its solution is below:
 The first example answer As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $(1, 2)$ $90$ degrees clockwise, the pipe at $(2, 3)$ $90$ degrees, the pipe at $(1, 6)$ $90$ degrees, the pipe at $(1, 7)$ $180$ degrees and the pipe at $(2, 7)$ $180$ degrees. Then the flow of water can reach $(2, n + 1)$ from $(1, 0)$ .
You have to answer $q$ independent queries.
输入格式
The first line of the input contains one integer $q$ ( $1 \le q \le 10^4$ ) — the number of queries. Then $q$ queries follow.
Each query consists of exactly three lines. The first line of the query contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $n$ digits from $1$ to $6$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes.
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$ .
Each query consists of exactly three lines. The first line of the query contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $n$ digits from $1$ to $6$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes.
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$ .
输出格式
For the $i$ -th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $(2, n + 1)$ from $(1, 0)$ , and "NO" otherwise.
输入输出样例
输入 #1
6 7 2323216 1615124 1 3 4 2 13 24 2 12 34 3 536 345 2 46 54
输出 #1
YES YES YES NO YES NO
The first query from the example is described in the problem statement.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted