#P6762. Counting Lego Block Configurations

    ID: 19970 Type: Default 1000ms 256MiB

Counting Lego Block Configurations

Counting Lego Block Configurations

We have an unlimited supply of 2×2 LEGO blocks in three colors: white (W), gray (G) and black (B). These blocks are used to build a structure on a 6×6 base plate. Each block must be placed aligned with the grid and entirely within the 6×6 boundary. In the final configuration a complete layer is formed by placing non‐overlapping 2×2 blocks so that the entire board is exactly covered. (Note that since 6 is divisible by 2, the board will be partitioned into nine 2×2 blocks.)

Furthermore, when a block is placed, all of its 4 cells must come from a valid placement (i.e. a block cannot be partially “floating” outside the board). Thus, in a valid configuration each of the nine 2×2 blocks has a uniform color.

After the blocks are placed, the front face of the board is observed and recorded as a 6×6 grid. Then, the board is rotated 90° counterclockwise about its vertical axis, and the (rotated) front view is recorded again as another 6×6 grid. Note that the rotated view is simply the original view rotated 90° counterclockwise.

Your task is: given the two 6×6 grids (the original view and the rotated view), determine the number of valid configurations that could have produced them. In our setting the only freedom is in the assignment (choice) of block colors. However, because the two views are provided, the configuration is uniquely determined if it is valid. Thus, if the views are consistent with a valid placement the answer is 1; otherwise it is 0.

Note: A valid configuration must satisfy both of the following conditions:

  1. Each 2×2 sub‐block (with top‐left corners at positions (0,0), (0,2), (0,4), (2,0), …, (4,4)) in both views is uniformly colored.
  2. The second (rotated) view must exactly equal the first view rotated 90° counterclockwise. In LaTeX, the rotation means that for all 0 ≤ r, c < 6, we require $$\text{rotated}[r][c] = \text{front}[c][5-r].$$

If both conditions hold, output 1; otherwise, output 0. (The answer is small so no modulo is needed.)

inputFormat

The input consists of 12 lines. The first 6 lines each contain 6 characters (without spaces) representing the front view of the board. The next 6 lines each contain 6 characters representing the rotated view (i.e. the front view after a 90° counterclockwise rotation). Each character will be one of 'W', 'G' or 'B'.

outputFormat

Output a single integer: 1 if the two views are consistent with a valid configuration, and 0 otherwise.

sample

WWBBGG
WWBBGG
BBGGWW
BBGGWW
GGWWBB
GGWWBB
GGWWBB
GGWWBB
BBGGWW
BBGGWW
WWBBGG
WWBBGG
1