/*
* let's for fixed width X find the maximum valid height Y, denote it by ans[X].
* upper bound of Y for every X is ans[1].
*
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>
using namespace std;
int main() {
int n, m, res = 0;
cin >> n >> m;
vector <vector <int>> a(n + 5, vector<int>(m + 5, 0));
for (int i = 1; i <= n; i++) {
scanf("\n");
for (int j = 1; j <= m; j++) {
char ch;
scanf("%c", &ch);
a[i][j] = ch - 48;
}
}
vector <vector <int>> up(n + 5, vector<int>(m + 5, 0));
vector <vector <int>> dn(n + 5, vector<int>(m + 5, 0));
for (int j = 1; j <= m; j++) {
for (int i = 1; i <= n; i++) {
up[i][j] = a[i][j] ? up[i - 1][j] + 1 : 0;
}
for (int i = n; i >= 1; i--) {
dn[i][j] = a[i][j] ? dn[i + 1][j] + 1 : 0;
}
}
vector <int> ans(m + 5, n);
for (int t = 0; t < 2; t++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j])
ans[1] = min(ans[1], up[i][j] + dn[i][j] - 1);
}
for (int j = 1; j <= m; j++) {
if (a[i][j] && !a[i][j - 1]) {
int min_d = n, min_u = n, k;
for (k = j; a[i][k]; k++) {
min_d = min(min_d, dn[i][k]);
min_u = min(min_u, up[i][k]);
ans[k - j + 1] = min(ans[k - j + 1], min_d + min_u - 1);
}
ans[k - j + 1] = 0;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j + j <= m; j++) {
swap(a[i][j], a[i][m - j + 1]);
swap(up[i][j], up[i][m - j + 1]);
swap(dn[i][j], dn[i][m - j + 1]);
}
}
}
for (int i = 1; i <= m; i++) {
ans[i] = min(ans[i], ans[i - 1]);
res = max(res, i * ans[i]);
//cout << i << " --> " << ans[i] << endl;
}
cout << res << endl;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("\n");
| ~~~~~^~~~~~
bomb.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf("%c", &ch);
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
408 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
400 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
8 ms |
1356 KB |
Output is correct |
28 |
Correct |
10 ms |
1780 KB |
Output is correct |
29 |
Correct |
12 ms |
1952 KB |
Output is correct |
30 |
Correct |
17 ms |
2784 KB |
Output is correct |
31 |
Correct |
14 ms |
2184 KB |
Output is correct |
32 |
Correct |
14 ms |
2340 KB |
Output is correct |
33 |
Correct |
18 ms |
2892 KB |
Output is correct |
34 |
Correct |
7 ms |
1356 KB |
Output is correct |
35 |
Correct |
17 ms |
2892 KB |
Output is correct |
36 |
Correct |
20 ms |
2912 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
727 ms |
74720 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
83 ms |
9680 KB |
Output is correct |
41 |
Correct |
1 ms |
292 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
696 ms |
74392 KB |
Output is correct |
44 |
Correct |
19 ms |
2892 KB |
Output is correct |
45 |
Correct |
692 ms |
74580 KB |
Output is correct |
46 |
Correct |
706 ms |
74480 KB |
Output is correct |
47 |
Correct |
689 ms |
74476 KB |
Output is correct |
48 |
Correct |
686 ms |
74456 KB |
Output is correct |
49 |
Correct |
712 ms |
74484 KB |
Output is correct |
50 |
Correct |
733 ms |
74460 KB |
Output is correct |
51 |
Correct |
698 ms |
74592 KB |
Output is correct |
52 |
Correct |
704 ms |
74480 KB |
Output is correct |
53 |
Correct |
696 ms |
74592 KB |
Output is correct |
54 |
Correct |
679 ms |
74480 KB |
Output is correct |
55 |
Correct |
676 ms |
74460 KB |
Output is correct |
56 |
Correct |
728 ms |
74460 KB |
Output is correct |
57 |
Correct |
679 ms |
74704 KB |
Output is correct |
58 |
Correct |
679 ms |
74564 KB |
Output is correct |
59 |
Correct |
672 ms |
74432 KB |
Output is correct |
60 |
Correct |
685 ms |
74516 KB |
Output is correct |
61 |
Correct |
715 ms |
74460 KB |
Output is correct |
62 |
Correct |
734 ms |
74456 KB |
Output is correct |
63 |
Correct |
723 ms |
74480 KB |
Output is correct |
64 |
Correct |
676 ms |
74692 KB |
Output is correct |
65 |
Correct |
685 ms |
74476 KB |
Output is correct |
66 |
Correct |
689 ms |
74436 KB |
Output is correct |
67 |
Correct |
701 ms |
74816 KB |
Output is correct |
68 |
Correct |
708 ms |
74584 KB |
Output is correct |
69 |
Correct |
674 ms |
74484 KB |
Output is correct |
70 |
Correct |
421 ms |
47944 KB |
Output is correct |
71 |
Correct |
665 ms |
74516 KB |
Output is correct |
72 |
Correct |
684 ms |
74480 KB |
Output is correct |
73 |
Correct |
672 ms |
74480 KB |
Output is correct |
74 |
Correct |
680 ms |
74844 KB |
Output is correct |
75 |
Correct |
683 ms |
74476 KB |
Output is correct |
76 |
Correct |
672 ms |
74480 KB |
Output is correct |
77 |
Correct |
693 ms |
74436 KB |
Output is correct |
78 |
Correct |
675 ms |
74692 KB |
Output is correct |
79 |
Correct |
663 ms |
74584 KB |
Output is correct |
80 |
Correct |
659 ms |
74580 KB |
Output is correct |
81 |
Correct |
659 ms |
74480 KB |
Output is correct |
82 |
Correct |
687 ms |
74776 KB |
Output is correct |
83 |
Correct |
685 ms |
74640 KB |
Output is correct |
84 |
Correct |
668 ms |
74476 KB |
Output is correct |
85 |
Correct |
688 ms |
74472 KB |
Output is correct |
86 |
Correct |
715 ms |
74468 KB |
Output is correct |
87 |
Correct |
674 ms |
74476 KB |
Output is correct |
88 |
Correct |
688 ms |
74576 KB |
Output is correct |
89 |
Correct |
699 ms |
74592 KB |
Output is correct |
90 |
Correct |
446 ms |
47944 KB |
Output is correct |
91 |
Correct |
687 ms |
74580 KB |
Output is correct |
92 |
Correct |
689 ms |
74720 KB |
Output is correct |
93 |
Correct |
707 ms |
74588 KB |
Output is correct |
94 |
Correct |
694 ms |
74472 KB |
Output is correct |
95 |
Correct |
685 ms |
74564 KB |
Output is correct |
96 |
Correct |
682 ms |
74436 KB |
Output is correct |
97 |
Correct |
725 ms |
74476 KB |
Output is correct |
98 |
Correct |
683 ms |
74564 KB |
Output is correct |
99 |
Correct |
699 ms |
74584 KB |
Output is correct |
100 |
Correct |
706 ms |
74504 KB |
Output is correct |