#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
#define PB push_back
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 2510;
const int oo = 2e9;
int n, m, ans, a[N][N], mx = oo, pr[N][N], best[N], nt[N][N], mnw = oo;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
char c; cin >> c;
a[i][j] = (c == '1' ? 1 : 0);
}
for (int j = 1; j <= m; j++){
for (int i = 1; i <= n; ){
if (a[i][j] == 0)
i++;
else {
int i1 = i;
while (i1 <= n && a[i1][j] == 1)
i1++;
mx = min(mx, i1 - i);
i = i1;
}
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; ){
if (a[i][j] == 0)
j++;
else {
int i1 = j;
while (i1 <= m && a[i][i1] == 1)
i1++;
mnw = min(mnw, i1 - j);
j = i1;
}
}
}
fill(best, best + n + 1, oo);
for (int i = 1; i <= n; i++){
int pre = 0;
for (int j = 1; j <= m; j++){
if (a[i][j] == 0)
pre = j;
pr[i][j] = pre + 1;
}
pre = m + 1;
for (int j = m; j > 0; j--){
if (a[i][j] == 0)
pre = j;
nt[i][j] = pre - 1;
}
}
for (int j = 1; j <= m; j++){
int lf = 0, rt = m + 1, len = 0;
for (int i = 1; i <= n; i++)
if (a[i][j] == 1){
lf = max(lf, pr[i][j]);
rt = min(rt, nt[i][j]);
len++;
best[len] = min(best[len], rt - lf + 1);
} else {
len = lf = 0;
rt = m + 1;
}
lf = 0, rt = m + 1, len = 0;
for (int i = n; i > 0; i--)
if (a[i][j] == 1){
lf = max(lf, pr[i][j]);
rt = min(rt, nt[i][j]);
len++;
best[len] = min(best[len], rt - lf + 1);
} else {
len = lf = 0;
rt = m + 1;
}
}
for (int i = 1; i <= mx; i++) {
if (best[i] == oo) return -1;
ans = max(ans, min(mnw, best[i]) * i);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
25 ms |
30456 KB |
Output is correct |
4 |
Correct |
25 ms |
30428 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
2 ms |
632 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
2 ms |
1144 KB |
Output is correct |
18 |
Correct |
3 ms |
1272 KB |
Output is correct |
19 |
Correct |
3 ms |
1656 KB |
Output is correct |
20 |
Correct |
3 ms |
1528 KB |
Output is correct |
21 |
Correct |
3 ms |
1016 KB |
Output is correct |
22 |
Correct |
3 ms |
1404 KB |
Output is correct |
23 |
Correct |
3 ms |
1656 KB |
Output is correct |
24 |
Correct |
3 ms |
1400 KB |
Output is correct |
25 |
Correct |
3 ms |
1656 KB |
Output is correct |
26 |
Correct |
3 ms |
1656 KB |
Output is correct |
27 |
Correct |
8 ms |
4928 KB |
Output is correct |
28 |
Correct |
8 ms |
5116 KB |
Output is correct |
29 |
Correct |
10 ms |
6520 KB |
Output is correct |
30 |
Correct |
12 ms |
7800 KB |
Output is correct |
31 |
Correct |
10 ms |
6264 KB |
Output is correct |
32 |
Correct |
11 ms |
7160 KB |
Output is correct |
33 |
Correct |
13 ms |
8184 KB |
Output is correct |
34 |
Correct |
8 ms |
5624 KB |
Output is correct |
35 |
Correct |
12 ms |
8184 KB |
Output is correct |
36 |
Correct |
14 ms |
8184 KB |
Output is correct |
37 |
Correct |
2 ms |
632 KB |
Output is correct |
38 |
Correct |
570 ms |
73976 KB |
Output is correct |
39 |
Correct |
2 ms |
504 KB |
Output is correct |
40 |
Correct |
61 ms |
19960 KB |
Output is correct |
41 |
Correct |
2 ms |
632 KB |
Output is correct |
42 |
Correct |
3 ms |
1656 KB |
Output is correct |
43 |
Correct |
505 ms |
74232 KB |
Output is correct |
44 |
Correct |
13 ms |
8184 KB |
Output is correct |
45 |
Correct |
467 ms |
74188 KB |
Output is correct |
46 |
Correct |
434 ms |
74236 KB |
Output is correct |
47 |
Correct |
468 ms |
74040 KB |
Output is correct |
48 |
Correct |
456 ms |
74052 KB |
Output is correct |
49 |
Correct |
573 ms |
74084 KB |
Output is correct |
50 |
Correct |
448 ms |
74232 KB |
Output is correct |
51 |
Correct |
450 ms |
74104 KB |
Output is correct |
52 |
Correct |
443 ms |
74104 KB |
Output is correct |
53 |
Correct |
446 ms |
74104 KB |
Output is correct |
54 |
Correct |
371 ms |
74072 KB |
Output is correct |
55 |
Correct |
369 ms |
74108 KB |
Output is correct |
56 |
Correct |
565 ms |
74316 KB |
Output is correct |
57 |
Correct |
357 ms |
74232 KB |
Output is correct |
58 |
Correct |
379 ms |
74232 KB |
Output is correct |
59 |
Correct |
359 ms |
74136 KB |
Output is correct |
60 |
Correct |
434 ms |
74104 KB |
Output is correct |
61 |
Correct |
568 ms |
74104 KB |
Output is correct |
62 |
Correct |
569 ms |
74232 KB |
Output is correct |
63 |
Correct |
572 ms |
74088 KB |
Output is correct |
64 |
Correct |
355 ms |
74084 KB |
Output is correct |
65 |
Correct |
427 ms |
74164 KB |
Output is correct |
66 |
Correct |
429 ms |
74068 KB |
Output is correct |
67 |
Correct |
485 ms |
74232 KB |
Output is correct |
68 |
Correct |
490 ms |
74344 KB |
Output is correct |
69 |
Correct |
373 ms |
74500 KB |
Output is correct |
70 |
Correct |
194 ms |
59612 KB |
Output is correct |
71 |
Correct |
336 ms |
74448 KB |
Output is correct |
72 |
Correct |
384 ms |
74468 KB |
Output is correct |
73 |
Correct |
376 ms |
74496 KB |
Output is correct |
74 |
Correct |
367 ms |
74464 KB |
Output is correct |
75 |
Correct |
371 ms |
74368 KB |
Output is correct |
76 |
Correct |
379 ms |
74356 KB |
Output is correct |
77 |
Correct |
382 ms |
74468 KB |
Output is correct |
78 |
Correct |
380 ms |
74352 KB |
Output is correct |
79 |
Correct |
296 ms |
74380 KB |
Output is correct |
80 |
Correct |
276 ms |
74464 KB |
Output is correct |
81 |
Correct |
283 ms |
74352 KB |
Output is correct |
82 |
Correct |
390 ms |
74344 KB |
Output is correct |
83 |
Correct |
389 ms |
74264 KB |
Output is correct |
84 |
Correct |
275 ms |
74268 KB |
Output is correct |
85 |
Correct |
372 ms |
74300 KB |
Output is correct |
86 |
Correct |
553 ms |
74360 KB |
Output is correct |
87 |
Correct |
364 ms |
74340 KB |
Output is correct |
88 |
Correct |
387 ms |
74360 KB |
Output is correct |
89 |
Correct |
435 ms |
74336 KB |
Output is correct |
90 |
Correct |
226 ms |
59600 KB |
Output is correct |
91 |
Correct |
400 ms |
74336 KB |
Output is correct |
92 |
Correct |
451 ms |
74340 KB |
Output is correct |
93 |
Correct |
552 ms |
75484 KB |
Output is correct |
94 |
Correct |
433 ms |
75540 KB |
Output is correct |
95 |
Correct |
390 ms |
75480 KB |
Output is correct |
96 |
Correct |
388 ms |
75368 KB |
Output is correct |
97 |
Correct |
566 ms |
75392 KB |
Output is correct |
98 |
Correct |
391 ms |
74664 KB |
Output is correct |
99 |
Correct |
429 ms |
75540 KB |
Output is correct |
100 |
Correct |
544 ms |
74516 KB |
Output is correct |