Problem of the day
‘GRID[i][j]’ = 0, if there is no building at cell (i, j).
Consider the following 2*2 ‘GRID[][]’:
[1, 2]
[3, 4]
Its projection in XY, YZ, XZ plane is shown below -:
Area covered in XY plane is 4, Area covered in YZ plane is 6, Area covered in ZX plane is 7, Thus the total area is 4 + 6 + 7 = 17.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single integer ‘N’, representing the dimensions of ‘GRID’
The next ‘N’ line of each test case will follow, each contains ‘N’ space-separated integers. These ‘N’ lines together represent the matrix ‘GRID[][]’.
For each test case, print a single integer that represents the total area of projections in the XY, YZ, and ZX plane.
Output for every test case will be printed in a separate line.
You don’t need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 50
2 <= N <= 1000
0 <= GRID[i][j] <= 100
Where ‘GRID[i][j]’ is the height of the building at cell (i, j).
Time limit: 1 sec
2
1
1
2
1 2
3 4
3
17
In the first test case, there is a 1*1 grid, and its only cell i.e cell (0, 0) has a building of height 1. Thus its projection in all three planes also takes area 1.
For the second test case, see the problem statement for an explanation.
2
3
0 0 0
0 0 0
0 0 0
3
1 1 1
1 0 1
1 1 1
0
14