#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 maxArea = 0;
for ( int w = 1; w <= m; w++ ) {
int h = n;
for ( int l = 0; l <= n; l++ ) {
//printf( "LINE %d:\n", l );
deque<int> dq;
for ( int c = 1; c <= m; c++ ) {
if ( !dq.empty() && dq.front() <= c - w )
dq.pop_front();
while ( !dq.empty() && up[l][c] <= up[l][dq.back()] )
dq.pop_back();
dq.push_back( c );
hup[c] = up[l][dq.front()];
}
while ( !dq.empty() )
dq.pop_back();
for ( int c = 1; c <= m; c++ ) {
if ( !dq.empty() && dq.front() <= c - w )
dq.pop_front();
while ( !dq.empty() && down[l + 1][c] <= down[l + 1][dq.back()] )
dq.pop_back();
dq.push_back( c );
hdown[c] = down[l + 1][dq.front()];
}
while ( !dq.empty() )
dq.pop_back();
//for ( int c = 1; c <= m; c++ )
//printf( "%d ", hup[c] );
//printf( "\n" );
//for ( int c = 1; c <= m; c++ )
//printf( "%d ", hdown[c] );
//printf( "\n" );
for ( int c = m; c >= 1; c-- ) {
if ( !dq.empty() && dq.front() >= c + w )
dq.pop_front();
while ( !dq.empty() && hdown[c] + hup[c] >= hdown[dq.back()] + hup[dq.back()] )
dq.pop_back();
dq.push_back( c );
maxHeight[c] = hdown[dq.front()] + hup[dq.front()];
}
for ( int c = 1; c <= m; c++ ) {
if ( mat[l][c] )
h = min( h, maxHeight[c] );
//printf( "%d ", mat[l][c] ? maxHeight[c] : 9 );
}
//printf( "\n" );
}
//printf( "\n\n\n\nBA AVEM W SI H!!!!!!!!!!! %d %d\n\n\n", w, h );
maxArea = max( maxArea, w * h );
}
cout << maxArea;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
12 ms |
30396 KB |
Output is correct |
4 |
Correct |
11 ms |
31580 KB |
Output is correct |
5 |
Correct |
132 ms |
2396 KB |
Output is correct |
6 |
Correct |
22 ms |
2396 KB |
Output is correct |
7 |
Incorrect |
1 ms |
2648 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
2652 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Incorrect |
0 ms |
600 KB |
Output isn't correct |
16 |
Correct |
1 ms |
608 KB |
Output is correct |
17 |
Correct |
6 ms |
1380 KB |
Output is correct |
18 |
Incorrect |
4 ms |
3256 KB |
Output isn't correct |
19 |
Incorrect |
8 ms |
1632 KB |
Output isn't correct |
20 |
Incorrect |
8 ms |
3420 KB |
Output isn't correct |
21 |
Incorrect |
5 ms |
2908 KB |
Output isn't correct |
22 |
Incorrect |
8 ms |
3344 KB |
Output isn't correct |
23 |
Correct |
13 ms |
1632 KB |
Output is correct |
24 |
Correct |
6 ms |
1368 KB |
Output is correct |
25 |
Incorrect |
13 ms |
1624 KB |
Output isn't correct |
26 |
Incorrect |
14 ms |
1624 KB |
Output isn't correct |
27 |
Incorrect |
289 ms |
4956 KB |
Output isn't correct |
28 |
Incorrect |
458 ms |
7008 KB |
Output isn't correct |
29 |
Incorrect |
550 ms |
8540 KB |
Output isn't correct |
30 |
Correct |
822 ms |
11708 KB |
Output is correct |
31 |
Correct |
679 ms |
10832 KB |
Output is correct |
32 |
Correct |
580 ms |
11232 KB |
Output is correct |
33 |
Incorrect |
958 ms |
12004 KB |
Output isn't correct |
34 |
Incorrect |
198 ms |
10172 KB |
Output isn't correct |
35 |
Incorrect |
933 ms |
11984 KB |
Output isn't correct |
36 |
Execution timed out |
1028 ms |
11988 KB |
Time limit exceeded |
37 |
Correct |
1 ms |
4440 KB |
Output is correct |
38 |
Execution timed out |
1056 ms |
80028 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Execution timed out |
1050 ms |
20572 KB |
Time limit exceeded |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
14 ms |
1628 KB |
Output is correct |
43 |
Execution timed out |
1101 ms |
79968 KB |
Time limit exceeded |
44 |
Correct |
993 ms |
11100 KB |
Output is correct |
45 |
Execution timed out |
1037 ms |
79984 KB |
Time limit exceeded |
46 |
Execution timed out |
1076 ms |
79952 KB |
Time limit exceeded |
47 |
Execution timed out |
1051 ms |
79860 KB |
Time limit exceeded |
48 |
Execution timed out |
1041 ms |
79888 KB |
Time limit exceeded |
49 |
Execution timed out |
1064 ms |
79956 KB |
Time limit exceeded |
50 |
Execution timed out |
1031 ms |
79792 KB |
Time limit exceeded |
51 |
Execution timed out |
1068 ms |
79920 KB |
Time limit exceeded |
52 |
Execution timed out |
1065 ms |
79944 KB |
Time limit exceeded |
53 |
Execution timed out |
1068 ms |
79956 KB |
Time limit exceeded |
54 |
Execution timed out |
1074 ms |
79788 KB |
Time limit exceeded |
55 |
Execution timed out |
1022 ms |
79952 KB |
Time limit exceeded |
56 |
Execution timed out |
1104 ms |
79956 KB |
Time limit exceeded |
57 |
Execution timed out |
1054 ms |
79956 KB |
Time limit exceeded |
58 |
Execution timed out |
1059 ms |
79960 KB |
Time limit exceeded |
59 |
Execution timed out |
1039 ms |
80032 KB |
Time limit exceeded |
60 |
Execution timed out |
1020 ms |
79952 KB |
Time limit exceeded |
61 |
Execution timed out |
1068 ms |
79904 KB |
Time limit exceeded |
62 |
Execution timed out |
1058 ms |
79780 KB |
Time limit exceeded |
63 |
Execution timed out |
1034 ms |
79936 KB |
Time limit exceeded |
64 |
Execution timed out |
1039 ms |
79952 KB |
Time limit exceeded |
65 |
Execution timed out |
1071 ms |
79956 KB |
Time limit exceeded |
66 |
Execution timed out |
1079 ms |
80212 KB |
Time limit exceeded |
67 |
Execution timed out |
1041 ms |
79952 KB |
Time limit exceeded |
68 |
Execution timed out |
1040 ms |
79952 KB |
Time limit exceeded |
69 |
Execution timed out |
1072 ms |
79956 KB |
Time limit exceeded |
70 |
Execution timed out |
1025 ms |
64592 KB |
Time limit exceeded |
71 |
Execution timed out |
1062 ms |
79784 KB |
Time limit exceeded |
72 |
Execution timed out |
1045 ms |
80028 KB |
Time limit exceeded |
73 |
Execution timed out |
1034 ms |
79784 KB |
Time limit exceeded |
74 |
Execution timed out |
1040 ms |
79892 KB |
Time limit exceeded |
75 |
Execution timed out |
1066 ms |
79792 KB |
Time limit exceeded |
76 |
Execution timed out |
1060 ms |
79956 KB |
Time limit exceeded |
77 |
Execution timed out |
1075 ms |
79960 KB |
Time limit exceeded |
78 |
Execution timed out |
1093 ms |
79812 KB |
Time limit exceeded |
79 |
Execution timed out |
1029 ms |
79956 KB |
Time limit exceeded |
80 |
Execution timed out |
1062 ms |
79952 KB |
Time limit exceeded |
81 |
Execution timed out |
1063 ms |
79956 KB |
Time limit exceeded |
82 |
Execution timed out |
1041 ms |
79952 KB |
Time limit exceeded |
83 |
Execution timed out |
1035 ms |
79984 KB |
Time limit exceeded |
84 |
Execution timed out |
1093 ms |
79952 KB |
Time limit exceeded |
85 |
Execution timed out |
1046 ms |
79916 KB |
Time limit exceeded |
86 |
Execution timed out |
1080 ms |
79956 KB |
Time limit exceeded |
87 |
Execution timed out |
1006 ms |
80032 KB |
Time limit exceeded |
88 |
Execution timed out |
1055 ms |
79936 KB |
Time limit exceeded |
89 |
Execution timed out |
1063 ms |
79952 KB |
Time limit exceeded |
90 |
Execution timed out |
1061 ms |
64732 KB |
Time limit exceeded |
91 |
Execution timed out |
1060 ms |
80004 KB |
Time limit exceeded |
92 |
Execution timed out |
1077 ms |
79796 KB |
Time limit exceeded |
93 |
Execution timed out |
1008 ms |
79888 KB |
Time limit exceeded |
94 |
Execution timed out |
1074 ms |
79956 KB |
Time limit exceeded |
95 |
Execution timed out |
1054 ms |
79952 KB |
Time limit exceeded |
96 |
Execution timed out |
1045 ms |
80024 KB |
Time limit exceeded |
97 |
Execution timed out |
1070 ms |
80004 KB |
Time limit exceeded |
98 |
Execution timed out |
1039 ms |
79952 KB |
Time limit exceeded |
99 |
Execution timed out |
1071 ms |
80012 KB |
Time limit exceeded |
100 |
Execution timed out |
1073 ms |
79780 KB |
Time limit exceeded |