#P12139. Black & White Chessboard Filling
Black & White Chessboard Filling
Black & White Chessboard Filling
Little Blue has recently become obsessed with a game called “Black & White Chessboard Filling”. The game is played on a 6×6 square grid. Some cells of the board are already filled with pieces (black or white), and the remaining cells are empty. To win the game you must fill in the blanks following these rules:
- Equal Number of Pieces: In every row and every column, the number of black pieces and white pieces must be equal.
- No Three Consecutive Identical Pieces: In any row or column, you cannot have more than two consecutive pieces of the same color (i.e. no "111" or "000").
- Unique Rows and Columns: The pattern of pieces in each row must be unique compared to every other row. Similarly, each column must have a unique pattern compared to every other column. (Note: rows and columns are not compared with each other.)
You are given a 6×6 board in which some cells are pre-filled. The pre-filled values are represented as follows: black pieces by 1 and white pieces by 0; empty cells are denoted by a period (.
).
Your task is to fill in the empty cells to complete the board so that it meets all the rules. The puzzle is guaranteed to have a unique solution.
Output the answer in a single line as a 36-digit string obtained by reading the board in row-major order (from left to right, top to bottom). For example, if the final board (for illustration purposes only) is:
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1
then the output should be:
100000000000000000001000001100001111
inputFormat
The input consists of 6 lines. Each line contains 6 tokens separated by spaces. Each token is either 1
(indicating a black piece), 0
(indicating a white piece), or .
(indicating an empty cell).
outputFormat
Output a single line containing a 36-digit string. This string is produced by concatenating the values in the filled board (with black pieces as 1 and white pieces as 0) in row-major order.
sample
1 1 . 0 . 0
. 0 1 . 0 1
. . . . . .
0 1 0 . 1 0
1 . 0 1 . 1
. 1 1 0 . 0
110010001101101001010110100101011010