fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int largestRectangle(vector<int>& h) {
  5. stack<int> st;
  6. int maxArea = 0;
  7. int n = h.size();
  8.  
  9. for (int i = 0; i <= n; i++) {
  10. int cur = (i == n ? 0 : h[i]);
  11.  
  12. while (!st.empty() && cur < h[st.top()]) {
  13. int height = h[st.top()];
  14. st.pop();
  15. int width = st.empty() ? i : i - st.top() - 1;
  16. maxArea = max(maxArea, height * width);
  17. }
  18.  
  19. st.push(i);
  20. }
  21.  
  22. return maxArea;
  23. }
  24.  
  25. int main() {
  26. ios::sync_with_stdio(false);
  27. cin.tie(nullptr);
  28.  
  29. vector<string> grid;
  30. string line;
  31.  
  32. while (getline(cin, line)) {
  33. if (!line.empty())
  34. grid.push_back(line);
  35. }
  36.  
  37. int n = grid.size();
  38. int m = grid[0].size();
  39.  
  40. vector<int> height(m, 0);
  41. int ans = 0;
  42.  
  43. for (int i = 0; i < n; i++) {
  44. for (int j = 0; j < m; j++) {
  45. if (grid[i][j] == '.')
  46. height[j]++;
  47. else
  48. height[j] = 0;
  49. }
  50.  
  51. ans = max(ans, largestRectangle(height));
  52. }
  53.  
  54. cout << ans;
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.01s 5316KB
stdin
............. .....
...... ... ...
.... ..... ... ...
.. ...... .....
............. ....
stdout
13