atcoder#AGC019D. [AGC019D] Shift and Flip
[AGC019D] Shift and Flip
Score : points
Problem Statement
You have two strings and of the same length consisting of and .
You can transform using the following operations in any order and as many times as you want:
- Shift by one character to the left (i.e., if , replace with ).
- Shift by one character to the right (i.e., if , replace with ).
- Choose any such that . Flip (i.e., set ).
You goal is to make strings and equal.
Print the smallest number of operations required to achieve this, or if the goal is unreachable.
Constraints
- and consist of and .
Input
Input is given from Standard Input in the following format:
Output
Print the smallest number of operations required to make strings and equal, or if the goal is unreachable.
1010
1100
3
Here is one fastest way to achieve the goal:
- Flip :
- Shift to the left:
- Flip again:
1
0
-1
There is no way to flip the only bit in .
11010
10001
4
Here is one fastest way to achieve the goal:
- Shift to the right:
- Flip :
- Shift to the left:
- Shift to the left again:
0100100
1111111
5
Flip , , , and in any order.