#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2500;
int mat[MAX_N + 2][MAX_N + 2], up[MAX_N + 2][MAX_N + 2], down[MAX_N + 2][MAX_N + 2], hup[MAX_N + 2], hdown[MAX_N + 2], maxHeight[MAX_N + 2];
int main() {
int n, m;
cin >> n >> m;
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ ) {
char ch;
cin >> ch;
mat[l][c] = ch - '0';
}
}
for ( int l = 1; l <= n; l++ ) {
for ( int c = 1; c <= m; c++ )
up[l][c] = (mat[l][c] ? up[l - 1][c] + 1 : 0);
}
for ( int l = n; l >= 1; l-- ) {
for ( int c = 1; c <= m; c++ )
down[l][c] = (mat[l][c] ? down[l + 1][c] + 1 : 0);
}
int maxWidth = m;
for ( int i = 0; i <= m; i++ )
maxHeight[i] = n;
for ( int l = 1; l <= n; l++ ) {
int cons1 = 0, hup = n, hdown = n;
for ( int c = 1; c <= m; c++ ) {
if ( mat[l][c] ) {
cons1++;
hup = min( hup, up[l][c] );
hdown = min( hdown, down[l][c] );
maxHeight[cons1] = min( maxHeight[cons1], hup + hdown - 1 );
} else {
if ( cons1 > 0 )
maxWidth = min( maxWidth, cons1 );
cons1 = 0, hup = n, hdown = n;
}
}
if ( cons1 > 0 )
maxWidth = min( maxWidth, cons1 );
}
for ( int l = 1; l <= n; l++ ) {
int cons1 = 0, hup = n, hdown = n;
for ( int c = m; c >= 1; c-- ) {
if ( mat[l][c] ) {
cons1++;
hup = min( hup, up[l][c] );
hdown = min( hdown, down[l][c] );
maxHeight[cons1] = min( maxHeight[cons1], hup + hdown - 1 );
} else
cons1 = 0, hup = n, hdown = n;
}
}
int maxArea = 0;
for ( int i = 1; i <= maxWidth; i++ ) {
maxHeight[i] = min( maxHeight[i], maxHeight[i - 1] );
maxArea = max( maxArea, maxHeight[i] * i );
}
cout << maxArea;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
30344 KB |
Output is correct |
4 |
Correct |
9 ms |
30512 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
1116 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
1 ms |
1628 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
1 ms |
1116 KB |
Output is correct |
22 |
Correct |
1 ms |
1372 KB |
Output is correct |
23 |
Correct |
2 ms |
1628 KB |
Output is correct |
24 |
Correct |
1 ms |
1372 KB |
Output is correct |
25 |
Correct |
1 ms |
1628 KB |
Output is correct |
26 |
Incorrect |
1 ms |
1628 KB |
Output isn't correct |
27 |
Incorrect |
5 ms |
4700 KB |
Output isn't correct |
28 |
Correct |
4 ms |
5244 KB |
Output is correct |
29 |
Correct |
6 ms |
6540 KB |
Output is correct |
30 |
Correct |
8 ms |
7772 KB |
Output is correct |
31 |
Correct |
7 ms |
6236 KB |
Output is correct |
32 |
Correct |
7 ms |
7004 KB |
Output is correct |
33 |
Correct |
8 ms |
8028 KB |
Output is correct |
34 |
Correct |
4 ms |
5572 KB |
Output is correct |
35 |
Correct |
9 ms |
8028 KB |
Output is correct |
36 |
Incorrect |
10 ms |
8116 KB |
Output isn't correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
219 ms |
73816 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
32 ms |
19964 KB |
Output is correct |
41 |
Correct |
0 ms |
604 KB |
Output is correct |
42 |
Correct |
1 ms |
1628 KB |
Output is correct |
43 |
Correct |
214 ms |
73816 KB |
Output is correct |
44 |
Correct |
10 ms |
8024 KB |
Output is correct |
45 |
Correct |
214 ms |
73688 KB |
Output is correct |
46 |
Correct |
201 ms |
73808 KB |
Output is correct |
47 |
Correct |
205 ms |
73812 KB |
Output is correct |
48 |
Correct |
231 ms |
73808 KB |
Output is correct |
49 |
Incorrect |
198 ms |
73828 KB |
Output isn't correct |
50 |
Correct |
215 ms |
73780 KB |
Output is correct |
51 |
Correct |
208 ms |
73704 KB |
Output is correct |
52 |
Correct |
227 ms |
73812 KB |
Output is correct |
53 |
Correct |
228 ms |
73812 KB |
Output is correct |
54 |
Correct |
211 ms |
73668 KB |
Output is correct |
55 |
Correct |
202 ms |
73712 KB |
Output is correct |
56 |
Correct |
196 ms |
73856 KB |
Output is correct |
57 |
Correct |
191 ms |
73804 KB |
Output is correct |
58 |
Correct |
196 ms |
73812 KB |
Output is correct |
59 |
Correct |
225 ms |
73692 KB |
Output is correct |
60 |
Incorrect |
213 ms |
73760 KB |
Output isn't correct |
61 |
Incorrect |
209 ms |
73812 KB |
Output isn't correct |
62 |
Incorrect |
238 ms |
73808 KB |
Output isn't correct |
63 |
Incorrect |
225 ms |
73808 KB |
Output isn't correct |
64 |
Incorrect |
246 ms |
73812 KB |
Output isn't correct |
65 |
Correct |
196 ms |
73812 KB |
Output is correct |
66 |
Correct |
212 ms |
73808 KB |
Output is correct |
67 |
Correct |
213 ms |
73668 KB |
Output is correct |
68 |
Correct |
212 ms |
73740 KB |
Output is correct |
69 |
Correct |
218 ms |
73812 KB |
Output is correct |
70 |
Correct |
146 ms |
58964 KB |
Output is correct |
71 |
Correct |
204 ms |
73808 KB |
Output is correct |
72 |
Correct |
209 ms |
73772 KB |
Output is correct |
73 |
Correct |
205 ms |
73688 KB |
Output is correct |
74 |
Correct |
213 ms |
73844 KB |
Output is correct |
75 |
Correct |
240 ms |
73812 KB |
Output is correct |
76 |
Correct |
209 ms |
73768 KB |
Output is correct |
77 |
Correct |
196 ms |
73808 KB |
Output is correct |
78 |
Correct |
236 ms |
73652 KB |
Output is correct |
79 |
Correct |
211 ms |
73816 KB |
Output is correct |
80 |
Correct |
214 ms |
73808 KB |
Output is correct |
81 |
Correct |
215 ms |
73808 KB |
Output is correct |
82 |
Correct |
212 ms |
73812 KB |
Output is correct |
83 |
Correct |
219 ms |
73808 KB |
Output is correct |
84 |
Correct |
207 ms |
73808 KB |
Output is correct |
85 |
Correct |
216 ms |
73768 KB |
Output is correct |
86 |
Correct |
218 ms |
73808 KB |
Output is correct |
87 |
Correct |
206 ms |
73856 KB |
Output is correct |
88 |
Correct |
254 ms |
73808 KB |
Output is correct |
89 |
Correct |
215 ms |
73672 KB |
Output is correct |
90 |
Correct |
135 ms |
58960 KB |
Output is correct |
91 |
Correct |
210 ms |
73812 KB |
Output is correct |
92 |
Correct |
208 ms |
73716 KB |
Output is correct |
93 |
Correct |
204 ms |
73852 KB |
Output is correct |
94 |
Correct |
213 ms |
73876 KB |
Output is correct |
95 |
Correct |
223 ms |
73812 KB |
Output is correct |
96 |
Correct |
226 ms |
73808 KB |
Output is correct |
97 |
Correct |
228 ms |
73808 KB |
Output is correct |
98 |
Correct |
227 ms |
73684 KB |
Output is correct |
99 |
Correct |
213 ms |
73808 KB |
Output is correct |
100 |
Correct |
208 ms |
73808 KB |
Output is correct |