[Solution] Complementary XOR Codeforces Solution
You have two binary strings and of length . You would like to make all the elements of both strings equal to . Unfortunately, you can modify the contents of these strings using only the following operation:
- You choose two indices and ();
- For every that respects , change to the opposite. That is, ;
- For every that respects either or , change to the opposite. That is, .
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 . It can be proven that if such chain of operations exists, one exists with at most operations.
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer () — the length of the strings.
The second line of each test case contains a binary string , consisting only of characters 0 and 1, of length .
The third line of each test case contains a binary string , consisting only of characters 0 and 1, of length .
It is guaranteed that sum of over all test cases doesn't exceed .
For each testcase, print first "YES" if it's possible to make all the elements of both strings equal to . Otherwise, print "NO". If the answer is "YES", on the next line print a single integer () — the number of operations. Then lines follows, each contains two integers and () — the description of the operation.
If there are several correct answers, print any of them.
In the first test case, we can perform one operation with and . So and string became equal to 000. , and string 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 .
In the fourth test case, we can perform an operation with and , then string became equal to 01, and string doesn't change. Then we perform an operation with and , then and . So both of string and became equal to 00.
In the fifth test case, we can perform an operation with and . Then string became equal to 011 and string became equal to 100. Then we can perform an operation with and , so both of string and became equal to 000.
No comments:
Post a Comment