CF1906B.Button Pressing

普及/提高-

通过率:0%

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 i1i - 1 (if i>1i > 1 ) and lamp i+1i + 1 (if i<Ni < 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.

输入格式

This problem has multiple test cases. The first line consists of an integer TT ( 1T10001 \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 ( 3N2000003 \le N \le 200\,000 ). The sum of NN over all test cases does not exceed 200000200\,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 .

输出格式

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.

输入输出样例

  • 输入#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: 01010111110111111010111001000101 \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.

首页