#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);
}
vector<int> withds;
for ( int i = 1; i <= 30 && i <= m; i++ )
withds.push_back( i );
for ( int i = 100; i <= m - 50; i += 300 )
withds.push_back( m );
if ( m > 30 ) {
for ( int i = m - 29; i <= m; i++ )
withds.push_back( i );
}
int maxArea = 0;
for ( int w: withds ) {
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 = 1; c <= m; c++ ) {
if ( hup[c] == 0 )
hdown[c] = 0;
}
for ( int c = m; c >= 1; c-- ) {
if ( !dq.empty() && dq.front() >= c + w )
dq.pop_front();
if ( c >= w ) {
while ( !dq.empty() && hdown[c] + hup[c] >= hdown[dq.back()] + hup[dq.back()] )
dq.pop_back();
dq.push_back( c );
}
if ( !dq.empty() )
maxHeight[c] = hdown[dq.front()] + hup[dq.front()];
else
maxHeight[c] = 0;
}
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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
30552 KB |
Output is correct |
4 |
Correct |
10 ms |
30552 KB |
Output is correct |
5 |
Correct |
4 ms |
348 KB |
Output is correct |
6 |
Incorrect |
2 ms |
496 KB |
Output isn't correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 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 |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
5 ms |
1116 KB |
Output is correct |
18 |
Correct |
4 ms |
1372 KB |
Output is correct |
19 |
Correct |
8 ms |
1628 KB |
Output is correct |
20 |
Correct |
6 ms |
1628 KB |
Output is correct |
21 |
Correct |
4 ms |
1116 KB |
Output is correct |
22 |
Correct |
6 ms |
1372 KB |
Output is correct |
23 |
Correct |
8 ms |
1624 KB |
Output is correct |
24 |
Correct |
5 ms |
1468 KB |
Output is correct |
25 |
Correct |
8 ms |
1624 KB |
Output is correct |
26 |
Correct |
9 ms |
1796 KB |
Output is correct |
27 |
Correct |
70 ms |
4952 KB |
Output is correct |
28 |
Correct |
86 ms |
5348 KB |
Output is correct |
29 |
Incorrect |
96 ms |
6744 KB |
Output isn't correct |
30 |
Correct |
124 ms |
8028 KB |
Output is correct |
31 |
Correct |
106 ms |
6372 KB |
Output is correct |
32 |
Correct |
114 ms |
7328 KB |
Output is correct |
33 |
Incorrect |
145 ms |
8284 KB |
Output isn't correct |
34 |
Correct |
58 ms |
5768 KB |
Output is correct |
35 |
Incorrect |
140 ms |
8444 KB |
Output isn't correct |
36 |
Correct |
163 ms |
8284 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Execution timed out |
1092 ms |
78944 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
616 KB |
Output is correct |
40 |
Incorrect |
608 ms |
20992 KB |
Output isn't correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Incorrect |
8 ms |
1728 KB |
Output isn't correct |
43 |
Execution timed out |
1084 ms |
78648 KB |
Time limit exceeded |
44 |
Incorrect |
148 ms |
8284 KB |
Output isn't correct |
45 |
Execution timed out |
1067 ms |
78676 KB |
Time limit exceeded |
46 |
Execution timed out |
1063 ms |
78676 KB |
Time limit exceeded |
47 |
Execution timed out |
1047 ms |
78548 KB |
Time limit exceeded |
48 |
Execution timed out |
1036 ms |
78760 KB |
Time limit exceeded |
49 |
Execution timed out |
1060 ms |
78676 KB |
Time limit exceeded |
50 |
Execution timed out |
1039 ms |
78588 KB |
Time limit exceeded |
51 |
Execution timed out |
1064 ms |
78628 KB |
Time limit exceeded |
52 |
Execution timed out |
1061 ms |
78672 KB |
Time limit exceeded |
53 |
Execution timed out |
1064 ms |
78676 KB |
Time limit exceeded |
54 |
Execution timed out |
1062 ms |
78676 KB |
Time limit exceeded |
55 |
Execution timed out |
1039 ms |
78528 KB |
Time limit exceeded |
56 |
Execution timed out |
1072 ms |
78676 KB |
Time limit exceeded |
57 |
Execution timed out |
1066 ms |
79444 KB |
Time limit exceeded |
58 |
Execution timed out |
1080 ms |
79508 KB |
Time limit exceeded |
59 |
Execution timed out |
1042 ms |
79440 KB |
Time limit exceeded |
60 |
Execution timed out |
1022 ms |
78548 KB |
Time limit exceeded |
61 |
Execution timed out |
1029 ms |
78672 KB |
Time limit exceeded |
62 |
Execution timed out |
1016 ms |
78700 KB |
Time limit exceeded |
63 |
Execution timed out |
1043 ms |
78700 KB |
Time limit exceeded |
64 |
Execution timed out |
1060 ms |
78676 KB |
Time limit exceeded |
65 |
Execution timed out |
1030 ms |
79440 KB |
Time limit exceeded |
66 |
Execution timed out |
1067 ms |
79448 KB |
Time limit exceeded |
67 |
Execution timed out |
1046 ms |
79496 KB |
Time limit exceeded |
68 |
Execution timed out |
1057 ms |
79400 KB |
Time limit exceeded |
69 |
Execution timed out |
1056 ms |
78708 KB |
Time limit exceeded |
70 |
Execution timed out |
1052 ms |
62544 KB |
Time limit exceeded |
71 |
Execution timed out |
1061 ms |
78592 KB |
Time limit exceeded |
72 |
Execution timed out |
1028 ms |
78696 KB |
Time limit exceeded |
73 |
Execution timed out |
1006 ms |
78676 KB |
Time limit exceeded |
74 |
Execution timed out |
1062 ms |
78556 KB |
Time limit exceeded |
75 |
Execution timed out |
1016 ms |
78540 KB |
Time limit exceeded |
76 |
Execution timed out |
1052 ms |
78752 KB |
Time limit exceeded |
77 |
Execution timed out |
1095 ms |
78728 KB |
Time limit exceeded |
78 |
Execution timed out |
1073 ms |
78676 KB |
Time limit exceeded |
79 |
Execution timed out |
1048 ms |
78680 KB |
Time limit exceeded |
80 |
Execution timed out |
1065 ms |
78672 KB |
Time limit exceeded |
81 |
Execution timed out |
1056 ms |
78616 KB |
Time limit exceeded |
82 |
Execution timed out |
1093 ms |
78540 KB |
Time limit exceeded |
83 |
Execution timed out |
1041 ms |
78676 KB |
Time limit exceeded |
84 |
Execution timed out |
1040 ms |
78732 KB |
Time limit exceeded |
85 |
Execution timed out |
1027 ms |
78672 KB |
Time limit exceeded |
86 |
Execution timed out |
1048 ms |
78672 KB |
Time limit exceeded |
87 |
Execution timed out |
1037 ms |
78616 KB |
Time limit exceeded |
88 |
Execution timed out |
1098 ms |
78676 KB |
Time limit exceeded |
89 |
Execution timed out |
1082 ms |
78672 KB |
Time limit exceeded |
90 |
Execution timed out |
1057 ms |
64048 KB |
Time limit exceeded |
91 |
Execution timed out |
1022 ms |
78672 KB |
Time limit exceeded |
92 |
Execution timed out |
1038 ms |
78572 KB |
Time limit exceeded |
93 |
Execution timed out |
1104 ms |
78528 KB |
Time limit exceeded |
94 |
Execution timed out |
1035 ms |
78676 KB |
Time limit exceeded |
95 |
Execution timed out |
1052 ms |
78560 KB |
Time limit exceeded |
96 |
Execution timed out |
1091 ms |
78672 KB |
Time limit exceeded |
97 |
Execution timed out |
1049 ms |
78672 KB |
Time limit exceeded |
98 |
Execution timed out |
1063 ms |
78596 KB |
Time limit exceeded |
99 |
Execution timed out |
1028 ms |
78672 KB |
Time limit exceeded |
100 |
Execution timed out |
1078 ms |
78676 KB |
Time limit exceeded |