Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- using namespace std;
- int maxSizeFromHistogram(int a[], int n)
- {
- stack<int> s;
- int maxArea = 0;
- int tp;
- int areaWithTop;
- int i = 0;
- while (i < n) {
- if (s.empty() || a[s.top()] <= a[i]) {
- s.push(i++);
- } else {
- tp = s.top(); s.pop();
- int w = s.empty() ? i : i - s.top() - 1;
- areaWithTop = a[tp] * w;
- if (maxArea < areaWithTop)
- maxArea = areaWithTop;
- }
- }
- while (!s.empty()) {
- tp = s.top(); s.pop();
- int w = s.empty() ? i : i - s.top() - 1;
- areaWithTop = a[tp] * w;
- if (maxArea < areaWithTop)
- maxArea = areaWithTop;
- }
- return maxArea;
- }
- int main()
- {
- int n; cin >> n;
- int a[n];
- for (int i = 0; i < n; i++)
- a[i] = 0;
- int _max = 0;
- for (int rowIndex = 0; rowIndex < n; rowIndex++)
- {
- for (int j = 0; j < n; j++)
- {
- int value; cin >> value;
- if (value == 0) a[j]++;
- else a[j] = 0;
- }
- int result = maxSizeFromHistogram(a, n);
- if (_max < result) _max = result;
- }
- cout << "Result: " << _max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement