Preparing NOJ

# G ? Area of Polycubes

1000ms 65536K

## Description:

A polycube is a solid made by gluing together unit cubes (one unit on each edge) on one or morefaces. The figure in the lower-left is not a polycube because some cubes are attached along anedge.

For this problem, the polycube will be formed from unit cubes centered at integer lattice points in3-space. The polycube will be built up one cube at a time, starting with a cube centered at (0,0,0). Ateach step of the process (after the first cube), the next cube must have a face in common with a cubepreviously included and not be the same as a block previously included. For example, a 1 -by-1 -by-5block (as shown above in the upper-left polycube) could be built up as:

(0,0,0) (0,0,1 ) (0,0,2) (0,0,3) (0,0,4)

and a 2-by-2-by-2 cube (upper-right figure) could be built as:

(0,0,0) (0,0,1 ) (0,1,1 ) (0,1, 0) (1,0,0) (1,0,1 ) (1,1,1 ) (1,1, 0)

Since the surface of the polycube is made up of unit squares, its area is an integer.Write a program which takes as input a sequence of integer lattice points in 3-space and determineswhether is correctly forms a polycube and, if so, what the surface area of the polycube is.

## Input:

The first line of input contains a single integer N, (1 ￡ N ￡ 1000) which is the number of data sets thatfollow. Each data set consists of multiple lines of input. The first line contains the number of points P,(1 = P = 100) in the problem instance. Each succeeding line contains the centers of the cubes, eightto a line (except possibly for the last line). Each center is given as 3 integers, separated by commas.The points are separated by a single space.

## Output:

For each data set, you should generate one line of output with the following values: The data setnumber as a decimal integer (start counting at one), a space and the surface area of the polycube if itis correctly formed, OR, if it is not correctly formed, the string “NO” a space and the index (startingwith 1) of the first cube which does not share a face with a previous cube. Note that the surface areaincludes the area of any included holes.

## Sample Input:

450,0,0 0,0,1 0,0,2 0,0, 3 0,0,480,0,0 0,0,1 0,1,0 0,1,1 1,0,0 1,0,1 1,1,0 1,1,140,0,0 0,0,1 1,1,0 1,1,1200,0,0 0,0,1 0,0,2 0,1,2 0,2,2 0,2,1 0,2,0 0,1,01,0,0 2,0,0 1,0,2 2,0,2 1,2,2 2,2,2 1,2,0 2,2,02,1,0 2,1,2 2,0,1 2,2,1

## Sample Output:

1 222 243 NO 34 72

## Note:

undefined

Info

Provider NOJ

Code NOJ1537

Tags

Submitted 2

Passed 1

AC Rate 50%

Date 04/20/2019 10:03:10

Related

Nothing Yet