auto optimize_cpp_stdio = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return0; }(); classSolution { public: conststaticint maxn = 1e5 + 10; conststaticint maxm = 1e5 + 10; constint INF = 0x3f3f3f3f; intlargestRectangleArea(vector<int> &heights) { int n = heights.size(); vector<int> st(n); int top = -1; int ans = 0; for (int i = 0; i < n; ++i) { while (top >= 0 && heights[st[top]] >= heights[i]) { int h = heights[st[top]]; int right = i - 1; --top; int left = top < 0 ? 0 : st[top] + 1; int w = right - left + 1; ans = max(ans, w * h); } st[++top] = i; } int size = st[top]; while (top >= 0) { int h = heights[st[top]]; int right = size; --top; int left = top < 0 ? 0 : st[top] + 1; int w = right - left + 1; ans = max(ans, w * h); } return ans; } intmaximalRectangle(vector<vector<char>> &matrix) { int n = matrix.size(), m = matrix[0].size(); vector<int> heights(m); int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (matrix[i][j] == '1') heights[j] += 1; else heights[j] = 0; } ans = max(ans, largestRectangleArea(heights)); } return ans; } };