#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<vector<int>> U(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0') {
continue;
}
U[i][j] = (i == 0 || s[i - 1][j] == '0' ? i : U[i - 1][j]);
}
}
vector<vector<int>> D(n, vector<int>(m));
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0') {
continue;
}
D[i][j] = (i == n - 1 || s[i + 1][j] == '0' ? i : D[i + 1][j]);
}
}
int width = m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0') {
continue;
}
int ptr = j;
while (ptr + 1 < m && s[i][ptr + 1] == '1') {
ptr += 1;
}
width = min(width, ptr - j + 1);
j = ptr;
}
}
int height = n;
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (s[i][j] == '0') {
continue;
}
int ptr = i;
while (ptr + 1 < n && s[ptr + 1][j] == '1') {
ptr += 1;
}
height = min(height, ptr - i + 1);
i = ptr;
}
}
vector<int> mx(m + 1, height);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0') {
continue;
}
int ptr = j;
while (ptr + 1 < m && s[i][ptr + 1] == '1') {
ptr += 1;
}
int L = 0, R = n;
for (int k = j; k <= ptr; k++) {
L = max(L, U[i][k]);
R = min(R, D[i][k]);
mx[k - j + 1] = min(mx[k - j + 1], R - L + 1);
}
j = ptr;
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 1; j >= 0; j--) {
if (s[i][j] == '0') {
continue;
}
int ptr = j;
while (ptr > 0 && s[i][ptr - 1] == '1'){
ptr -= 1;
}
int L = 0, R = n;
for (int k = j; k >= ptr; k--) {
L = max(L, U[i][k]);
R = min(R, D[i][k]);
mx[j - k + 1] = min(mx[j - k + 1], R - L + 1);
}
j = ptr;
}
}
for (int i = 1; i < width; i++) {
mx[i + 1] = min(mx[i + 1], mx[i]);
}
int res = 0;
for (int i = 1; i <= width; i++) {
res = max(res, mx[i] * i);
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
1116 KB |
Output is correct |
28 |
Correct |
2 ms |
1484 KB |
Output is correct |
29 |
Correct |
2 ms |
1368 KB |
Output is correct |
30 |
Correct |
3 ms |
2140 KB |
Output is correct |
31 |
Correct |
2 ms |
1624 KB |
Output is correct |
32 |
Correct |
2 ms |
1880 KB |
Output is correct |
33 |
Correct |
3 ms |
2136 KB |
Output is correct |
34 |
Correct |
1 ms |
1112 KB |
Output is correct |
35 |
Correct |
2 ms |
2140 KB |
Output is correct |
36 |
Correct |
3 ms |
2140 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
84 ms |
56292 KB |
Output is correct |
39 |
Correct |
1 ms |
520 KB |
Output is correct |
40 |
Correct |
10 ms |
7260 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
79 ms |
56280 KB |
Output is correct |
44 |
Correct |
3 ms |
2140 KB |
Output is correct |
45 |
Correct |
79 ms |
56156 KB |
Output is correct |
46 |
Correct |
81 ms |
56148 KB |
Output is correct |
47 |
Correct |
79 ms |
56280 KB |
Output is correct |
48 |
Correct |
92 ms |
56400 KB |
Output is correct |
49 |
Correct |
83 ms |
56284 KB |
Output is correct |
50 |
Correct |
80 ms |
56144 KB |
Output is correct |
51 |
Correct |
83 ms |
56144 KB |
Output is correct |
52 |
Correct |
77 ms |
56280 KB |
Output is correct |
53 |
Correct |
83 ms |
56284 KB |
Output is correct |
54 |
Correct |
74 ms |
56228 KB |
Output is correct |
55 |
Correct |
79 ms |
56288 KB |
Output is correct |
56 |
Correct |
87 ms |
56400 KB |
Output is correct |
57 |
Correct |
81 ms |
56292 KB |
Output is correct |
58 |
Correct |
73 ms |
56284 KB |
Output is correct |
59 |
Correct |
73 ms |
56148 KB |
Output is correct |
60 |
Correct |
78 ms |
56244 KB |
Output is correct |
61 |
Correct |
85 ms |
56284 KB |
Output is correct |
62 |
Correct |
89 ms |
56280 KB |
Output is correct |
63 |
Correct |
85 ms |
56212 KB |
Output is correct |
64 |
Correct |
80 ms |
56284 KB |
Output is correct |
65 |
Correct |
77 ms |
56148 KB |
Output is correct |
66 |
Correct |
79 ms |
56148 KB |
Output is correct |
67 |
Correct |
83 ms |
56288 KB |
Output is correct |
68 |
Correct |
93 ms |
56280 KB |
Output is correct |
69 |
Correct |
74 ms |
56288 KB |
Output is correct |
70 |
Correct |
42 ms |
36184 KB |
Output is correct |
71 |
Correct |
83 ms |
56404 KB |
Output is correct |
72 |
Correct |
85 ms |
56400 KB |
Output is correct |
73 |
Correct |
87 ms |
56100 KB |
Output is correct |
74 |
Correct |
77 ms |
56064 KB |
Output is correct |
75 |
Correct |
74 ms |
56284 KB |
Output is correct |
76 |
Correct |
73 ms |
56280 KB |
Output is correct |
77 |
Correct |
85 ms |
56404 KB |
Output is correct |
78 |
Correct |
74 ms |
56280 KB |
Output is correct |
79 |
Correct |
65 ms |
56144 KB |
Output is correct |
80 |
Correct |
64 ms |
56144 KB |
Output is correct |
81 |
Correct |
67 ms |
56284 KB |
Output is correct |
82 |
Correct |
96 ms |
56144 KB |
Output is correct |
83 |
Correct |
94 ms |
56096 KB |
Output is correct |
84 |
Correct |
64 ms |
56216 KB |
Output is correct |
85 |
Correct |
74 ms |
56144 KB |
Output is correct |
86 |
Correct |
86 ms |
56280 KB |
Output is correct |
87 |
Correct |
99 ms |
56288 KB |
Output is correct |
88 |
Correct |
74 ms |
56292 KB |
Output is correct |
89 |
Correct |
76 ms |
56144 KB |
Output is correct |
90 |
Correct |
46 ms |
36188 KB |
Output is correct |
91 |
Correct |
76 ms |
56288 KB |
Output is correct |
92 |
Correct |
80 ms |
56148 KB |
Output is correct |
93 |
Correct |
83 ms |
56056 KB |
Output is correct |
94 |
Correct |
78 ms |
56288 KB |
Output is correct |
95 |
Correct |
76 ms |
56156 KB |
Output is correct |
96 |
Correct |
73 ms |
56208 KB |
Output is correct |
97 |
Correct |
84 ms |
56292 KB |
Output is correct |
98 |
Correct |
74 ms |
56408 KB |
Output is correct |
99 |
Correct |
76 ms |
56144 KB |
Output is correct |
100 |
Correct |
85 ms |
56060 KB |
Output is correct |