-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathM0005.cpp
More file actions
40 lines (36 loc) · 801 Bytes
/
M0005.cpp
File metadata and controls
40 lines (36 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Problem Statement: https://www.hackerrank.com/challenges/3d-surface-area/problem
*/
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int surfaceArea(vector<vector<int>> A) {
int area = 2 * (A.size() - 2) * (A[A.size() - 2].size() - 2);
for(int i=1 ; i<A.size()-1 ; i++)
for(int j=1 ; j<A[i].size()-1 ; j++){
area += 4*A[i][j];
area -= 2*min(A[i][j], A[i][j+1]);
area -= 2*min(A[i][j], A[i+1][j]);
}
return area;
}
int main()
{
int H, W, num;
vector<vector<int>> A;
cin>>H>>W;
A.push_back(vector<int>(W+2));
for(int i=1 ; i<=H ; i++){
A.push_back(vector<int>());
A[i].push_back(0);
for(int j=1 ; j<=W ; j++){
cin>>num;
A[i].push_back(num);
}
A[i].push_back(0);
}
A.push_back(vector<int>(W+2));
cout<<surfaceArea(A);
return 0;
}