QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#10559. Button Pressing

統計

现有 $N$ 个按钮(编号从 1 到 $N$)和 $N$ 盏灯(编号从 1 到 $N$)。每盏灯要么亮,要么灭。初始时,如果 $A_i = 1$,则第 $i$ 盏灯亮;如果 $A_i = 0$,则第 $i$ 盏灯灭。

按钮 $i$ 连接到灯 $i - 1$(如果 $i > 1$)和灯 $i + 1$(如果 $i < N$)。在一次操作中,你仅能在第 $i$ 盏灯亮时按下按钮 $i$。按下按钮后,与该按钮相连的灯的状态会发生翻转。形式化地说,如果灯之前是灭的,则会变亮;如果灯之前是亮的,则会变灭。注意,灯 $i$ 本身不与按钮 $i$ 相连,因此按下按钮 $i$ 不会改变灯 $i$ 的状态。

经过零次或多次操作后,你希望第 $i$ 盏灯的状态满足:如果 $B_i = 1$ 则亮,如果 $B_i = 0$ 则灭。请判断是否可以达成目标。

输入格式

本题包含多个测试用例。第一行包含一个整数 $T$ ($1 \le T \le 1000$),表示测试用例的数量。每个测试用例包含三行。

每个测试用例的第一行包含一个整数 $N$ ($3 \le N \le 200\,000$)。所有测试用例的 $N$ 之和不超过 $200\,000$。

每个测试用例的第二行包含一个长度为 $N$ 的字符串 $A$。每个字符为 0 或 1,第 $i$ 个字符表示第 $i$ 盏灯的初始状态。

每个测试用例的第三行包含一个长度为 $N$ 的字符串 $B$。每个字符为 0 或 1,第 $i$ 个字符表示第 $i$ 盏灯的目标状态。

输出格式

对于每个测试用例,如果可以通过零次或多次操作达到所有灯的目标状态,则输出 YES,否则输出 NO。

样例

输入 1

2
4
0101
0100
3
000
010

输出 1

YES
NO

说明 1

对于第一个测试用例,依次按下按钮 4, 2, 4, 3, 1, 2,灯的状态变化如下:0101 $\to$ 0111 $\to$ 1101 $\to$ 1111 $\to$ 1010 $\to$ 1110 $\to$ 0100。

对于第二个测试用例,你无法按下任何按钮,因此无法达到目标状态。

输入 2

5
7
0101011
1111010
5
11111
00000
4
1101
1101
6
101010
100100
3
000
000

输出 2

NO
NO
YES
YES
YES

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.