Matrix and Volume
Practice
3 (1 votes)
Algorithms
Graphs
Hard
Problem
80% Success 830 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a large box of length X, width Y and height Z. This box is entirely made up of small cubic boxes of 1 unit volume each i.e. length of cube is 1 unit. Now some cubes were removed to create empty spaces. All the cubes that were not removed stay fixed in their initial position.

Now you are given the information of the new state of the large box i.e. you are given the status of each cube that was used in making the larger box. If the status is 1 then it means that this cubic block was not removed or else if the status is 0 then it corresponds to the fact that this cubic block was removed.
Important Notes :
- Two blocks are adjacent if they share a face.
- A cube with edge size as 1 contains 1 unit cube volume.

Your task is to find the volume of air that can stay trapped inside the box in the new state if all the empty space is filed with air. The trapped air means that it should not come outside the box in an infinite amount of time.

Input format
- First line of input contains T denoting number of test cases.
- First line of each test case contains \(X,Y,Z\), the length, width and height of the box.
- You are also given with the Z sets of \( X*Y \) 2D matrices, each representing a layer of the box.

Output format
In a single line, return the volume of air that can be trapped.

Constraints

\(1 \le T \le 10 \)

\(1 \le X, Y, Z \le 10^{2} \)

\(0 \le A_{i,j,k} \le 1 \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
4 votes
Tags:
Dynamic ProgrammingAlgorithmsGraphsDepth First Search
Points:50
2 votes
Tags:
AlgorithmsDepth First SearchGraphsHard
Points:50
3 votes
Tags:
Dynamic ProgrammingTreeGraphsAlgorithmsDepth First Search