#ahc019a. [ahc019_a]Silhouette Block Puzzle Creation
[ahc019_a]Silhouette Block Puzzle Creation
Problem Statement
AtCoder is developing an educational toy that combines blocks to create a three-dimensional object with a specified silhouette. The toy consists of a set of polycube-shaped blocks consisting of cubes joined face to face and a pair of two 2D monochrome silhouette images. You will win the game if you can construct a single 3D object by combining the blocks, so that the two silhouettes of the created object, viewed from the front and from the right side, completely match the given silhouette images.
In order to allow children to play for a long time, we want to prepare multiple pairs of silhouettes for a single set of blocks. For example, the set of 6 blocks shown on the left figure can be used to create two pairs of silhouettes, as shown on the right.
As a toy designer, you are given two pairs of front/right silhouettes, and your task is to find a set of blocks from which you can construct two objects having the given pairs of silhouettes, and a way to construct them. Because children may accidentally swallow small blocks, sets of blocks consisting only of a small number of large blocks are preferable.
Detailed puzzle rules
- You don't have to use all the blocks (but you will get a better score if you do).
- Each block can be rotated by 90 degrees around the x-axis, y-axis, and z-axis, but cannot be flipped.
- The blocks must be arranged so that each vertex has integer coordinates, and different blocks must not have a positive common volume.
- The constructed object do not have to be connected. For the sake of simplicity, we assume that a floating arrangement is also possible (you may interpret this as there are a large number of additional transparent blocks, which can be used to support blocks).
About silhouette
Take the x-axis from left to right, the y-axis from front to back, and the z-axis from top to bottom. We assume that all blocks are within a cubic region that has and as diagonal corners. We define a three-dimensional 01-array as if some block occupies the cubic region that has and as diagonal corners, and otherwise. Then, the silhouette viewed from the front is a two-dimensional 01-array defined as follows.
\[ f(z,x)=\begin{cases} 1&(\sum_{y=0}^{D-1}b(x,y,z)\geq 1)\\ 0&(\sum_{y=0}^{D-1}b(x,y,z)=0) \end{cases} \]
Similarly, the silhouette viewed from the right is a two-dimensional 01-array , defined as follows
\[ r(z,y)=\begin{cases} 1&(\sum_{x=0}^{D-1}b(x,y,z)\geq 1)\\ 0&(\sum_{x=0}^{D-1}b(x,y,z)=0) \end{cases} \]
Scoring
Let be the volume of each block in the created toy set. Here, the volume of a block is equal to the number of cubes it comprises. Each block must be connected, i.e., every cube it comprises must be reachable by moving through shared faces. If there is a disconnected block, it will be judged as WA