-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10074-Take the Land
55 lines (50 loc) · 1.4 KB
/
10074-Take the Land
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main() {
int N, M;
while (cin >> N >> M && N != 0 && M != 0) {
int number;
vector<int> vec;
vector<vector<int>> mp;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
cin>>number;
vec.push_back(number);
}
mp.push_back(vec);
vec.clear();
}
int maxArea = 0;
vector<int> height(M, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (mp[i][j] == 0) {
height[j]++;
} else {
height[j] = 0;
}
}
stack<int> stk;
height.push_back(0);
for (int j = 0; j < height.size(); j++) {
while (!stk.empty() && height[j] < height[stk.top()]) {
int h = height[stk.top()];
stk.pop();
int w = 0;
if(stk.empty()){
w = j;
}
else{
w = j - stk.top() - 1;
}
maxArea = max(maxArea, h * w);
}
stk.push(j);
}
height.pop_back();
}
cout << maxArea << endl;
}
}