#C9295. Binary String Transformation
Binary String Transformation
Binary String Transformation
You are given two binary strings ( s ) and ( t ) each of length ( n ). The task is to determine whether it is possible to transform string ( s ) into string ( t ) by swapping any adjacent characters any number of times. It can be shown that such a transformation is possible if and only if the frequencies of the characters in ( s ) and ( t ) are the same, i.e., [ #0(s) = #0(t) \quad \text{and} \quad #1(s) = #1(t) ] If these conditions hold, output "YES"; otherwise, output "NO".
Note: The transformation does not require minimizing the number of swaps; it simply verifies the possibility of reordering via adjacent swaps.
inputFormat
The input is provided via standard input (stdin) with three lines:
- The first line contains an integer ( n ) representing the length of the binary strings.
- The second line contains the binary string ( s ) of length ( n ).
- The third line contains the binary string ( t ) of length ( n ).
outputFormat
Output a single line to standard output (stdout) containing either "YES" if string ( s ) can be transformed into ( t ) using any number of adjacent swaps, or "NO" otherwise.## sample
3
111
111
YES
</p>