Statement
Double Chocolate, or Double Choco, is a logic puzzle on a grid. Each cell is colored either white or gray, and some cells contain a positive integer. The player must divide the entire grid into one or more regions, satisfying all the rules below:
- Every region contains exactly one orthogonally connected white region and exactly one such gray region, and the two regions must be congruent (have the same shape and size) up to rotation and reflection.
- Each region may contain at most one cell with an integer. If it has one, the number of white cells (resp. gray cells) in that region must be equal to that number.
- No borders should be drawn between two cells in the same region.
The following is an example Double Chocolate puzzle with its solution.
The following are examples of non-solutions.
- The number of white cells in a region does not match the number in that region; a region contains two or more numbers
- A region contains only white or only gray cells
- White or gray cells in a region are not orthogonally connected
- Unnecessary border is drawn
- The white cells and gray cells in a region are not congruent
Given a Double Chocolate puzzle and a proposed solution, determine if the proposed solution is correct.
Input
The first line contains an even integer , the size of the square grid. ()
The next lines describe a Double Chocolate puzzle. The first lines contain the color information: the -th number of the -th line is 1 if the cell at row and column is gray, and 0 if white.
Output
If the proposed solution is indeed a valid solution to the puzzle, output 1. Otherwise, output 0.