#P15778. [JAG 2025 Summer Camp #3] Spray on Surface

[JAG 2025 Summer Camp #3] Spray on Surface

题目描述

Consider an N×N×NN \times N \times N region with opposite corners at (0,0,0)(0,0,0) and (N,N,N)(N,N,N).

Within this region, an object is built from 1×1×11 \times 1 \times 1 blocks. Each block occupies exactly the unit cube [i,i+1]×[j,j+1]×[k,k+1][i, i+1] \times [j, j+1] \times [k, k+1] for some integers 0i,j,k<N0 \leq i, j, k < N. It is guaranteed that this object is connected and that it contains no cavities (i.e., every empty cell is connected to the exterior of the N×N×NN \times N \times N region).

You want to know the amount of spray paint required to paint the surface of this object. Compute the surface area of the object.

输入格式

The input consists of multiple test cases.

The first line contains an integer TT (1T1001 \leq T \leq 100), representing the number of test cases.

TT test cases follow. Each test case is given in the following format.

$$\begin{aligned} & N \\ & S_{1,1} \\ & S_{1,2} \\ & \vdots \\ & S_{1,N} \\ & S_{2,1} \\ & \vdots \\ & S_{N-1,N} \\ & S_{N,1} \\ & \vdots \\ & S_{N,N} \end{aligned} $$

For each test case, the first line contains an integer NN (1N101 \leq N \leq 10), representing the side length of the region containing the object.

The following N2N^2 lines each contain a string Si,jS_{i,j} of length NN, representing the shape of the object. If the kk-th character of Si,jS_{i,j} is ‘#’, then there is a block in the region [i,i+1]×[j,j+1]×[k,k+1][i, i+1] \times [j, j+1] \times [k, k+1]. If it is ‘.’, there is no block in that region. The object satisfies the conditions in the problem statement.

输出格式

For the TT test cases, output the answers on separate lines. For each test case, output the surface area of the object on a single line.

2
2
##
#.
#.
..
3
###
#.#
###
###
#.#
###
###
#.#
###
18
64