CF1906B.Button Pressing

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given NN buttons (numbered from 11 to NN) and NN lamps (numbered from 11 to NN). Each lamp can either be on or off. Initially, lamp ii is on if Ai=1A_i = 1, and off if Ai=0A_i = 0.

Button ii is connected to lamp i−1i - 1 (if i>1i \gt 1) and lamp i+1i + 1 (if i<Ni \lt N). In one move, you can press a button ii only if lamp ii is on. When a button is pressed, the state of the lamps connected to this button is toggled. Formally, the lamps will be on if it was off previously, and the lamps will be off if it was on previously. Note that lamp ii is not connected to button ii, thus, the state of lamp ii does not change if button ii is pressed.

After zero or more moves, you want lamp ii to be on if Bi=1B_i = 1, and off if Bi=0B_i = 0. Determine if it is possible to achieve this task.

你有 NN 个按钮(编号从 11 到 NN)和 NN 盏灯(编号从 11 到 NN)。每盏灯的状态为“开”或“关”。初始时,若 Ai=1A_i = 1,则第 ii 盏灯为“开”;若 Ai=0A_i = 0,则为“关”。

按钮 ii 连接着灯 i−1i - 1(当 i>1i > 1 时)和灯 i+1i + 1(当 i<Ni < N 时)。每次操作中,你仅可在灯 ii 处于“开”状态时按下按钮 ii。按下按钮 ii 后,所有与该按钮相连的灯的状态将被翻转:即原本“关”的变为“开”,原本“开”的变为“关”。注意,灯 ii 并不连接到按钮 ii,因此按下按钮 ii 不会改变灯 ii 的状态。

经过零次或多次操作后,你希望灯 ii 处于“开”状态当且仅当 Bi=1B_i = 1,处于“关”状态当且仅当 Bi=0B_i = 0。请判断是否能达成这一目标。

输入格式

This problem has multiple test cases. The first line consists of an integer TT (1≤T≤10001 \leq T \leq 1000), which represents the number of test cases. Each test case consists of three lines.

The first line of each test case consists of an integer NN (3≤N≤200 0003 \le N \le 200\,000). The sum of NN over all test cases does not exceed 200 000200\,000.

The second line of each test case consists of a string AA of length NN. Each character of AA can either be 0 or 1. The ii-th character represents the initial state of lamp ii.

The third line of each test case consists of a string AA of length NN. Each character of BB can either be 0 or 1. The ii-th character represents the desired final state of lamp ii.

本题包含多个测试用例。第一行是一个整数 TT(1≤T≤10001 \leq T \leq 1000),表示测试用例的数量。每个测试用例由三行组成。

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

每个测试用例的第二行包含一个长度为 NN 的字符串 AA。字符串 AA 的每个字符为 0 或 1,其中第 ii 个字符表示第 ii 盏灯的初始状态。

每个测试用例的第三行包含一个长度为 NN 的字符串 BB。字符串 BB 的每个字符为 0 或 1,其中第 ii 个字符表示第 ii 盏灯的目标最终状态。

输出格式

For each test case, output YES in a single line if the final state of all lamps can be reached after zero or more moves, or NO otherwise.

对于每个测试用例,如果经过零次或多次操作后可以达到所有灯的最终状态,则在一行中输出 YES;否则输出 NO。

输入输出样例

  • 输入#1

    2
    4
    0101
    0100
    3
    000
    010

    输出#1

    YES
    NO
  • 输入#2

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

    输出#2

    NO
    NO
    YES
    YES
    YES

说明/提示

Explanation for the sample input/output #1

For the first test case, by pressing the buttons 4,2,4,3,1,24, 2, 4, 3, 1, 2 in sequence, the condition of the buttons changes as: 0101→0111→1101→1111→1010→1110→01000101 \rightarrow 0111 \rightarrow 1101 \rightarrow 1111 \rightarrow 1010 \rightarrow 1110 \rightarrow 0100.

For the second test case, you are unable to press any button, hence it is impossible to reach the final state.

样例输入/输出 #1 的解释

对于第一个测试用例,依次按下按钮 4,2,4,3,1,24, 2, 4, 3, 1, 2 后,按钮状态的变化过程为:0101→0111→1101→1111→1010→1110→01000101 \rightarrow 0111 \rightarrow 1101 \rightarrow 1111 \rightarrow 1010 \rightarrow 1110 \rightarrow 0100。

对于第二个测试用例,你无法按下任何按钮,因此不可能达到最终状态。

输入解题思路,AI测评打分。不知道怎么写?

首页