CF1750C.Complementary XOR

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have two binary strings aa and bb of length nn . You would like to make all the elements of both strings equal to 00 . Unfortunately, you can modify the contents of these strings using only the following operation:

  • You choose two indices ll and rr ( 1lrn1 \le l \le r \le n );
  • For every ii that respects lirl \le i \le r , change aia_i to the opposite. That is, ai:=1aia_i := 1 - a_i ;
  • For every ii that respects either 1i<l1 \le i < l or r<inr < i \le n , change bib_i to the opposite. That is, bi:=1bib_i := 1 - b_i .

Your task is to determine if this is possible, and if it is, to find such an appropriate chain of operations. The number of operations should not exceed n+5n + 5 . It can be proven that if such chain of operations exists, one exists with at most n+5n + 5 operations.

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt ( 1t1051 \leq t \leq 10^5 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn ( 2n21052 \le n \le 2 \cdot 10^5 ) — the length of the strings.

The second line of each test case contains a binary string aa , consisting only of characters 0 and 1, of length nn .

The third line of each test case contains a binary string bb , consisting only of characters 0 and 1, of length nn .

It is guaranteed that sum of nn over all test cases doesn't exceed 21052 \cdot 10^5 .

输出格式

For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to 00 . Otherwise, print "NO". If the answer is "YES", on the next line print a single integer kk ( 0kn+50 \le k \le n + 5 ) — the number of operations. Then kk lines follows, each contains two integers ll and rr ( 1lrn1 \le l \le r \le n ) — the description of the operation.

If there are several correct answers, print any of them.

输入输出样例

  • 输入#1

    5
    3
    010
    101
    2
    11
    10
    4
    1000
    0011
    2
    10
    10
    3
    111
    111

    输出#1

    YES
    1
    2 2
    NO
    NO
    YES
    2
    1 2
    2 2
    YES
    2
    1 1
    2 3

说明/提示

In the first test case, we can perform one operation with l=2l = 2 and r=2r = 2 . So a2:=11=0a_2 := 1 - 1 = 0 and string aa became equal to 000. b1:=11=0b_1 := 1 - 1 = 0 , b3:=11=0b_3 := 1 - 1 = 0 and string bb became equal to 000.

In the second and in the third test cases, it can be proven that it's impossible to make all elements of both strings equal to 00 .

In the fourth test case, we can perform an operation with l=1l = 1 and r=2r = 2 , then string aa became equal to 01, and string bb doesn't change. Then we perform an operation with l=2l = 2 and r=2r = 2 , then a2:=11=0a_2 := 1 - 1 = 0 and b1=11=0b_1 = 1 - 1 = 0 . So both of string aa and bb became equal to 00.

In the fifth test case, we can perform an operation with l=1l = 1 and r=1r = 1 . Then string aa became equal to 011 and string bb became equal to 100. Then we can perform an operation with l=2l = 2 and r=3r = 3 , so both of string aa and bb became equal to 000.

首页