-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (70 loc) · 1.41 KB
/
main.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
const size_t MAX_SIZE = 501;
size_t CurrentAreaWidthCalculator(stack <size_t> *st, size_t pos) {
if (!st->empty()) {
return pos - st->top() - 1;
}
return pos;
}
size_t MaxHistogramArea(int *arr, size_t size) {
stack <size_t> st;
size_t area_max = 0;
size_t stack_top = 0;
size_t area_current = 0;
size_t i = 0;
while (i < size || !st.empty()) {
if ((st.empty() || arr[st.top()] <= arr[i]) && i < size) {
st.push(i);
i++;
} else {
stack_top = st.top();
st.pop();
area_current = arr[stack_top] * CurrentAreaWidthCalculator(&st, i);
if (area_current > area_max) {
area_max = area_current;
}
}
}
return area_max;
}
int main(void) {
size_t height;
size_t width;
cin >> height >> width;
char map[MAX_SIZE][MAX_SIZE];
for (size_t i = 0; i < height; i++) {
for (size_t j = 0; j < width; j++) {
char in_tmp;
cin >> in_tmp;
if (in_tmp == '1') {
map[i][j] = 0;
} else {
map[i][j] = 1;
}
}
}
int tmp[MAX_SIZE];
for (size_t i = 0; i < width; i++) {
tmp[i] = 0;
}
size_t res = 0;
for (size_t i = 0; i < height; i++) {
for (size_t j = 0; j < width; j++) {
if (map[i][j] != 0) {
tmp[j]++;
} else {
tmp[j] = 0;
}
}
size_t res_tmp = MaxHistogramArea(tmp, width);
if (res_tmp > res) {
res = res_tmp;
}
}
cout << res << endl;
return 0;
}