c++(20ms 99%) simple, easy, small (commented)
\n\n\n\nGeneral idea : do precalculating contigious ones (vertical and horizontal)\n\nRuntime: 20 ms, faster than 98.92% of C++ online submissions for Maximal R
\n![image](https://assets.leetcode.com/users/images/3dd5e53c-fa9c-4ad9-b765-67145629724c_1637224731.3485026.png)\n\n\n**General idea : do precalculating contigious ones (vertical and horizontal)**\n\nRuntime: 20 ms, faster than 98.92% of C++ online submissions for Maximal Rectangle.\nMemory Usage: 12.1 MB, less than 53.69% of C++ online submissions for Maximal Rectangle.\n```\nclass Solution {\npublic:\n  int maximalRectangle(vector<vector<char>>& matrix) {\n    if(matrix.empty()) return 0;\n    int y = matrix.size(), x = matrix[0].size(), answer = 0;\n    vector<vector<int>> a(y,vector<int>(x)), b(y,vector<int>(x));\n    \n    for(int j = 0; j != x; j++)\n      for(int i = y - 1, k = 0; i >= 0; i--)\n        if(matrix[i][j] == \'1\') a[i][j] = ++k;\n        else a[i][j] = k = 0;\n      \n    for(int i = 0; i != y; i++)\n      for(int j = x - 1, k = 0; j >= 0; j--)\n        if(matrix[i][j] == \'1\') b[i][j] = ++k;\n        else b[i][j] = k = 0;\n    \n    for(int i = 0; i != y; i++)\n      for(int j = 0; j != x; j++){\n        int Y = a[i][j], X = b[i][j];\n        for(int w = j + 1, lim = j + X; w < lim; w++)\n          if(Y > a[i][w]) {answer = max(answer, Y * (w - j)); Y = a[i][w];}\n        \n        answer = max(answer, Y * X);\n      }\n            \n    return answer;\n  }\n};\n```
['C', 'C++']