Can we transform given strings to get the same string?

30 Views Asked by At

There are 2 binaries string $A, B$ (string just contains $0$ or $1$)

Input: $A_1, A_2,\dots,A_{50}$ and $B_1, B_2,\dots,B_{50}$

Note that: $A_{51} = B_{51} = A_{52} = B_{52} = \dots = A_{\inf} = B_{\inf} = 0$

Output: Can we transform A, B to 2 equal string ? YES or NO

Transformations can be used: $\text{aab} \leftrightarrows \text{bba}$ and $1c_1c_20 \leftrightarrows 0c_1c_21$


My first idea is use bidirectional search to solve this problem but I think It is inefficient.

1

There are 1 best solutions below

0
On

Here is an invariant that can help to detect non equivalent string.

Let $p_i = \sum{A_{3*n+i}} \mod{2}$

If $p_1=p_2=p_3$, it must stay that way. If there are 2 different values, it will also stay that way