March Break Contest '22 Problem 6 - A Binary String Problem

View as PDF

Submit solution

Points: 10
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Clay has a binary string S of length N. By definition, a binary string consists only of 1s and 0s.

Clay is able to perform two operations on the string:

  • Bitwise XOR (\oplus) a length M substring with X (where X is a binary string of length M)
  • Swap two adjacent bits

Both operations have a cost of 1 to perform. Given his starting string and a target string, what is the minimum cost needed to convert from the starting string to the target string?

Input Specification

The first line contains N (1 \le N \le 20). The second line contains S, a binary string of length N.

The third line contains M (1 \le N \le N). The fourth line contains X, a binary string of length M.

The final line of input contains the target string.

Output Specification

Output an integer representing the minimum cost needed to convert from the starting string to the target string, or -1 if the target string is impossible to reach.

Sample Input

5
10110
3
111
01001

Sample Output

2

Explanation

The target string can be created if you XOR the substring from index 0 to 2 with X and swap indices 3 and 4.


Comments

There are no comments at the moment.