Largest area of rectangle with permutations
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| int Solution::solve(vector<vector<int> > &A) { int n = A.size(), m = A[0].size(), res = 0; for(int i = 0; i < n; i++) { vector<int> now; for(int j = 0; j < m; j++) { if(i and A[i][j]) A[i][j] += A[i-1][j]; if(A[i][j]) now.push_back(A[i][j]); } sort(rbegin(now), rend(now)); for(int j = 0; j < now.size(); j++) res = max(res, (j + 1) * now[j]); } return res; }
|