1727.cpp (640B)
1 class Solution { 2 public: 3 int largestSubmatrix(vector<vector<int>> &matrix) { 4 const int n = matrix.size(), m = matrix[0].size(); 5 vector<int> height(m, 0); 6 int ans = 0; 7 8 for (int i = 0; i < n; i++) { 9 for (int j = 0; j < m; j++) { 10 if (matrix[i][j] == 0) 11 height[j] = 0; 12 else 13 height[j] += 1; 14 } 15 16 vector<int> order = height; 17 sort(begin(order), end(order)); 18 19 for (int j = 0; j < m; j++) 20 ans = max(ans, order[j] * (m - j)); 21 } 22 return ans; 23 } 24 };