class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int a[1000];
memset(a, 0, sizeof(a));
int sum = 0;
int howlong = 0;
for (vector<vector<int>>::iterator it = grid.begin(); it != grid.end();
++it) {
if ((*it).size() > howlong)howlong = (*it).size();
int maxn = 0;
for (int i = 0; i < (*it).size(); ++i) {
//top
if ((*it)[i] != 0)++sum;
//front
if ((*it)[i] > maxn)maxn = (*it)[i];
//side
if ((*it)[i] > a[i])a[i] = (*it)[i];
}
sum += maxn;
}
for (int i = 0; i < howlong; ++i)sum += a[i];
return sum;
}
};