Surface Area of Cubes
InterviewTime limit5sMemory limit512 MB
Given an A x B x C block of unit cubes with N cubes removed (including interior ones), compute the total surface area including surfaces of interior cavities.
- Level
Medium5 of 10
- Topics
- Hash map, Math, Implementation, Geometry
- Solved
- No attempts yet
Problem
Taro likes a single player game called "Surface Area of Cubes".
In this game, he initially has an rectangular solid formed by unit cubes (which are all 1 by 1 by 1 cubes). The center of each unit cube is placed at 3-dimensional coordinates where are all integers . Then the game master removes distinct unit cubes from the rectangular solid. After the cubes are removed, he must state the total surface area of this object exactly in order to win the game.
The removal operation does not change the positions of the cubes that are not removed. Not only the cubes on the surface of the rectangular solid but also the cubes inside can be removed. The object can also be split into multiple parts by the removal of the cubes. A player of this game has to count the surface areas that are not accessible from the outside as well.
Taro knows how many cubes were removed and which ones, but this game is very difficult for him, so he wants to win by cheating! You are Taro's friend, and your job is to write a program that calculates the total surface area of the object on Taro's behalf when you are given the size of the rectangular solid and the coordinates of the removed cubes.
Input
The input is formatted as follows.
The first line of a test case contains four integers , and
Each of the next lines contains non-negative integers , and which represent the coordinate of a removed cube. You may assume that these coordinates are distinct.
Output
Output the total surface area of the object from which the cubes were removed.