include iostream include string include vector include iomanip include

 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
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
const int N = 1000;
string rows[N];
int maxUp[N][N];
int smallerToLeft[N];
int smallerToRight[N];
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i)
cin >> rows[i];
for (int j = 0; j < m; ++j)
maxUp[0][j] = rows[0][j] - '0';
for (int i = 1; i < n; ++i)
for (int j = 0; j < m; ++j){
if (rows[i][j] == '0') maxUp[i][j] = 0;
else maxUp[i][j] = 1 + maxUp[i - 1][j];
}
int ans = 0;
for (int i = 0; i < n; ++i){
int* h = maxUp[i];
for (int j = 0; j < m; ++j){
smallerToLeft[j] = j - 1;
while (smallerToLeft[j] >= 0 && h[smallerToLeft[j]] >= h[j])
smallerToLeft[j] = smallerToLeft[smallerToLeft[j]];
}
for (int j = m - 1; j >= 0; --j)
{
smallerToRight[j] = j + 1;
while (smallerToRight[j] < m && h[smallerToRight[j]] >= h[j])
smallerToRight[j] = smallerToRight[smallerToRight[j]];
}
for (int j = 0; j < m; ++j)
{
int lb = smallerToLeft[j] + 1;
int rb = smallerToRight[j] - 1;
ans = max(ans, (rb - lb + 1) * h[j]);
}
}
cout << ans << endl;
return 0;
}