PROBLEM STATEMENT
Given two matrices a and b, both composed of zeroes and ones, return the minimal number of
operations necessary to transform matrix a into matrix b. An operation consists of flipping (one
becomes zero and zero becomes one) all elements of some contiguous 3 x 3 submatrix. If a cannot be
transformed into b, return -1.
DEFINITION
Class:MatrixTransforming
Method:minPushes
Parameters:vector , vector
Returns:int
Method signature:int minPushes(vector a, vector b)
CONSTRAINTS
-a will contain between 1 and 50 elements, inclusive.
-a and b will contain the same number of elements.
-Each element of a will contain between 1 and 50 characters, inclusive.
-Each element of b will contain between 1 and 50 characters, inclusive.
-All elements of a and b will contain the same number of characters.
-Each element of a and b will be contain only zeroes ('0') and ones ('1').
EXAMPLES
0)
{"111","111","111"}
{"000","000","000"}
Returns: 1
Flip the entire 3 x 3 matrix.
1)
{"1"}
{"0"}
Returns: -1
No flip can be made here.
2)
{"001","100","100","000","011","010","100","100","010",
"010","010","110","101","101","000","110","000","110"}
{"001","100","011","000","100","010","011","100","101",
"101","010","001","010","010","111","110","111","001"}
Returns: 7
3)
{
"0000",
"0010",
"0000"
}
{
"1001",
"1011",
"1001"
}
Returns: 2
Flip each of the two 3 x 3 submatrices once.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any
unauthorized use or reproduction of this information without the prior written consent of
TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.