fork download
  1. class Solution {
  2. public:
  3. int maximalRectangle(vector<vector<char>>& f) {
  4. int rows = f.size(), cols = f[0].size();
  5. vector<int> a(cols,0);
  6. int fin = 0;
  7. for (int i = 0; i < rows; i++) {
  8. for (int j = 0; j < cols; j++) {
  9. if (f[i][j] == '1') a[j]++;
  10. else a[j] = 0;
  11. }
  12. for (auto j:a) cout << j << " ";
  13. cout << "\n";
  14. int n = cols;
  15. vector<int> pre(n,0);
  16. vector<int> suf(n,n - 1);
  17. stack<int> s;
  18. for (int i = 0; i < n; i++) {
  19. if (s.empty()) {
  20. s.push(i);
  21. }else {
  22. while (!s.empty() && a[s.top()] >= a[i]) s.pop();
  23. if (!s.empty()) pre[i] = s.top() + 1;
  24. s.push(i);
  25. }
  26. }
  27. while (!s.empty()) s.pop();
  28.  
  29. for (int i = n - 1; i >= 0; i--) {
  30. if (s.empty()) {
  31. s.push(i);
  32. }else {
  33. while (!s.empty() && a[s.top()] >= a[i]) s.pop();
  34. if (!s.empty()) suf[i] = s.top() - 1;
  35. s.push(i);
  36. }
  37. }
  38. int ans = 0;
  39. for (int i = 0; i < n; i++) {
  40. ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
  41. ans = max(ans,a[i]);
  42. }
  43. fin = max(fin,ans);
  44. }
  45. return fin;
  46. }
  47. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:26: error: ‘vector’ has not been declared
     int maximalRectangle(vector<vector<char>>& f) {
                          ^~~~~~
prog.cpp:3:32: error: expected ‘,’ or ‘...’ before ‘<’ token
     int maximalRectangle(vector<vector<char>>& f) {
                                ^
prog.cpp: In member function ‘int Solution::maximalRectangle(int)’:
prog.cpp:4:20: error: ‘f’ was not declared in this scope
         int rows = f.size(), cols = f[0].size();
                    ^
prog.cpp:5:9: error: ‘vector’ was not declared in this scope
         vector<int> a(cols,0);
         ^~~~~~
prog.cpp:5:16: error: expected primary-expression before ‘int’
         vector<int> a(cols,0);
                ^~~
prog.cpp:8:31: error: ‘cols’ was not declared in this scope
           for (int j = 0; j < cols; j++) {
                               ^~~~
prog.cpp:8:31: note: suggested alternative: ‘rows’
           for (int j = 0; j < cols; j++) {
                               ^~~~
                               rows
prog.cpp:9:33: error: ‘a’ was not declared in this scope
             if (f[i][j] == '1') a[j]++;
                                 ^
prog.cpp:10:18: error: ‘a’ was not declared in this scope
             else a[j] = 0;
                  ^
prog.cpp:12:23: error: ‘a’ was not declared in this scope
           for (auto j:a) cout << j << " ";
                       ^
prog.cpp:12:26: error: ‘cout’ was not declared in this scope
           for (auto j:a) cout << j << " ";
                          ^~~~
prog.cpp:13:11: error: ‘cout’ was not declared in this scope
           cout << "\n";
           ^~~~
prog.cpp:14:19: error: ‘cols’ was not declared in this scope
           int n = cols;
                   ^~~~
prog.cpp:14:19: note: suggested alternative: ‘rows’
           int n = cols;
                   ^~~~
                   rows
prog.cpp:15:18: error: expected primary-expression before ‘int’
           vector<int> pre(n,0);
                  ^~~
prog.cpp:16:18: error: expected primary-expression before ‘int’
           vector<int> suf(n,n - 1);
                  ^~~
prog.cpp:17:11: error: ‘stack’ was not declared in this scope
           stack<int> s;
           ^~~~~
prog.cpp:17:17: error: expected primary-expression before ‘int’
           stack<int> s;
                 ^~~
prog.cpp:19:17: error: ‘s’ was not declared in this scope
             if (s.empty()) {
                 ^
prog.cpp:22:36: error: ‘a’ was not declared in this scope
               while (!s.empty() && a[s.top()] >= a[i]) s.pop();
                                    ^
prog.cpp:23:31: error: ‘pre’ was not declared in this scope
               if (!s.empty()) pre[i] = s.top() + 1;
                               ^~~
prog.cpp:27:19: error: ‘s’ was not declared in this scope
           while (!s.empty()) s.pop();
                   ^
prog.cpp:30:17: error: ‘s’ was not declared in this scope
             if (s.empty()) {
                 ^
prog.cpp:33:36: error: ‘a’ was not declared in this scope
               while (!s.empty() && a[s.top()] >= a[i]) s.pop();
                                    ^
prog.cpp:34:31: error: ‘suf’ was not declared in this scope
               if (!s.empty()) suf[i] = s.top() - 1;
                               ^~~
prog.cpp:40:28: error: ‘suf’ was not declared in this scope
             ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
                            ^~~
prog.cpp:40:37: error: ‘pre’ was not declared in this scope
             ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
                                     ^~~
prog.cpp:40:51: error: ‘a’ was not declared in this scope
             ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
                                                   ^
prog.cpp:40:19: error: ‘max’ was not declared in this scope
             ans = max(ans,(suf[i] - pre[i] + 1) * a[i]);
                   ^~~
prog.cpp:43:17: error: ‘max’ was not declared in this scope
           fin = max(fin,ans);
                 ^~~
stdout
Standard output is empty