Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views1 page

Problem I: Inversing Palindrome: Input

The document presents a problem involving two binary strings, a and b, where the goal is to determine if string a can be transformed into string b by flipping even-length palindromic substrings. It outlines the input format, including multiple test cases, and provides sample input and output for clarity. The constraints ensure that the total length of strings across all test cases does not exceed 200,000 characters.

Uploaded by

kimminjib574
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Problem I: Inversing Palindrome: Input

The document presents a problem involving two binary strings, a and b, where the goal is to determine if string a can be transformed into string b by flipping even-length palindromic substrings. It outlines the input format, including multiple test cases, and provides sample input and output for clarity. The constraints ensure that the total length of strings across all test cases does not exceed 200,000 characters.

Uploaded by

kimminjib574
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Problem I: Inversing Palindrome

You are given two zero-indexed binary strings a and b, each string having length n. You can
perform the following operation any number of times (possibly zero):

• Choose a palindromic substring of a with an even length, and flip all digits in the chosen
substring (every digit 0 is turned into digit 1, and vice-versa).

Determine whether it is possible to transform string a into string b.

Input
The first line contains a positive integer t (1 ≤ t ≤ 104 ) – the number of test cases. The
description of each test case is as follows.
The first line contains a positive integer n (2 ≤ n ≤ 100) – the length of the two binary strings.
The second line contains a binary string a of length n.
The third line contains a binary string b of length n.
It is guaranteed that the sum of n over all test cases does not exceed 2 · 105 .

Output
For each test case, print "YES" (without quotes) if you can transform string a into string b.
Otherwise, print "NO" (without quotes).

Sample Explanation
In the first test case, a possible way to transform string a into string b is described as follows:
[0;3] [3;4]
10010 −−→ 01100 −−→ 01111

In the second test case, it is impossible to perform any operation on string a. Therefore, it is
impossible to transform string a into a different string.
In the third test case, no operation is need to transform string a into string b.

Sample Input 1 Sample Output 1


3 YES
5 NO
10010 YES
01111
3
101
110
4
0000
0000

Vietnam National 2024 Problem I: Inversing Palindrome 17

You might also like