Given a partially filled grid with N rows and M columns and each gird with a number.We define
sumBlack is the sum of all Black gird and
sumWhite is the sum of all White gird.
You are to calculate how many ways there are to fill the remaining part of the grid under the constraints stated below to make the
absolute of (sumBlack - sumWhite) minimum and output one of these ways (if any exist).
Each cell in the grid should be colored either black or white.
All black cells in the grid should be connected with each other, and all white cells should also be connected with each other.The pictures below show two filled grids where this constraint is only fulfilled in the picture2.
There must be no
2x2 blocks in the grid which consists of only white cells, or of only black cells.
The picture3 shows a grid with a black and a white
2x2 block, while the picture4 contains no such
2x2 block.
You are not allowed to change the color of any of the cells whose color has already been assigned in the input, and all cells must be colored.