#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> g(n);
for (int i = 0; i < n; i++)
{
cin >> g[i];
}
int xx = INF, yy = INF;
{
for (int i = 0; i < n; i++)
{
int l = 0, r = 0;
while (l < m)
{
while (l < m && g[i][l] == '0')
{
l++;
}
if (l == m)
{
break;
}
r = l;
while (r < m && g[i][r] == '1')
{
r++;
}
xx = min(xx, r - l);
l = r;
}
}
for (int j = 0; j < m; j++)
{
int l = 0, r = 0;
while (l < n)
{
while (l < n && g[l][j] == '0')
{
l++;
}
if (l == n)
{
break;
}
r = l;
while (r < n && g[r][j] == '1')
{
r++;
}
yy = min(yy, r - l);
l = r;
}
}
}
vector<int> res(yy, xx);
auto solve = [&]()
{
vector<vector<int>> rr(n, vector<int>(m));
for (int i = 0; i < n; i++)
{
int cur = m;
for (int j = m - 1; j >= 0; j--)
{
if (g[i][j] == '0')
{
cur = j;
}
rr[i][j] = cur;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (g[i][j] == '1' && (i == 0 || g[i - 1][j] == '0') && (j == 0 || g[i][j - 1] == '0'))
{
int k = i, cur = INF;
while (k < n && k - i < res.size() && g[k][j] == '1')
{
cur = min(cur, rr[k][j] - j);
res[k - i] = min(res[k - i], cur);
k++;
}
res.resize(k - i);
}
}
}
};
for (int tt = 0; tt < 2; tt++)
{
solve();
reverse(g.begin(), g.end());
solve();
for (int i = 0; i < n; i++)
{
reverse(g[i].begin(), g[i].end());
}
}
int ans = 0;
for (int i = 0; i < res.size(); i++)
{
ans = max(ans, (i + 1) * res[i]);
}
cout << ans << '\n';
return 0;
}
Compilation message
bomb.cpp: In lambda function:
bomb.cpp:85:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | while (k < n && k - i < res.size() && g[k][j] == '1')
| ~~~~~~^~~~~~~~~~~~
bomb.cpp: In function 'int main()':
bomb.cpp:107:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int i = 0; i < res.size(); i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
388 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
988 KB |
Output is correct |
29 |
Correct |
2 ms |
1012 KB |
Output is correct |
30 |
Correct |
3 ms |
1372 KB |
Output is correct |
31 |
Correct |
2 ms |
1196 KB |
Output is correct |
32 |
Correct |
3 ms |
1152 KB |
Output is correct |
33 |
Correct |
4 ms |
1460 KB |
Output is correct |
34 |
Correct |
2 ms |
860 KB |
Output is correct |
35 |
Correct |
3 ms |
1460 KB |
Output is correct |
36 |
Correct |
4 ms |
1460 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
116 ms |
31736 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Incorrect |
13 ms |
4344 KB |
Output isn't correct |
41 |
Correct |
1 ms |
544 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
122 ms |
31660 KB |
Output is correct |
44 |
Correct |
4 ms |
1460 KB |
Output is correct |
45 |
Correct |
118 ms |
31772 KB |
Output is correct |
46 |
Correct |
121 ms |
31820 KB |
Output is correct |
47 |
Correct |
118 ms |
31756 KB |
Output is correct |
48 |
Correct |
125 ms |
31724 KB |
Output is correct |
49 |
Correct |
119 ms |
31768 KB |
Output is correct |
50 |
Correct |
114 ms |
31688 KB |
Output is correct |
51 |
Correct |
116 ms |
31888 KB |
Output is correct |
52 |
Correct |
111 ms |
31768 KB |
Output is correct |
53 |
Correct |
110 ms |
31776 KB |
Output is correct |
54 |
Correct |
109 ms |
31832 KB |
Output is correct |
55 |
Correct |
114 ms |
31760 KB |
Output is correct |
56 |
Correct |
125 ms |
31744 KB |
Output is correct |
57 |
Correct |
110 ms |
31728 KB |
Output is correct |
58 |
Correct |
106 ms |
31768 KB |
Output is correct |
59 |
Correct |
109 ms |
31848 KB |
Output is correct |
60 |
Correct |
109 ms |
31752 KB |
Output is correct |
61 |
Correct |
118 ms |
31768 KB |
Output is correct |
62 |
Correct |
116 ms |
31652 KB |
Output is correct |
63 |
Correct |
116 ms |
31756 KB |
Output is correct |
64 |
Correct |
107 ms |
31772 KB |
Output is correct |
65 |
Correct |
111 ms |
31764 KB |
Output is correct |
66 |
Correct |
120 ms |
31768 KB |
Output is correct |
67 |
Correct |
111 ms |
31688 KB |
Output is correct |
68 |
Correct |
114 ms |
31684 KB |
Output is correct |
69 |
Correct |
107 ms |
31752 KB |
Output is correct |
70 |
Correct |
67 ms |
20376 KB |
Output is correct |
71 |
Correct |
105 ms |
31772 KB |
Output is correct |
72 |
Correct |
122 ms |
31756 KB |
Output is correct |
73 |
Correct |
109 ms |
31688 KB |
Output is correct |
74 |
Correct |
107 ms |
31816 KB |
Output is correct |
75 |
Correct |
104 ms |
31772 KB |
Output is correct |
76 |
Correct |
106 ms |
31752 KB |
Output is correct |
77 |
Correct |
107 ms |
31684 KB |
Output is correct |
78 |
Correct |
107 ms |
31768 KB |
Output is correct |
79 |
Correct |
109 ms |
32012 KB |
Output is correct |
80 |
Correct |
105 ms |
31772 KB |
Output is correct |
81 |
Correct |
104 ms |
31768 KB |
Output is correct |
82 |
Correct |
108 ms |
31744 KB |
Output is correct |
83 |
Correct |
111 ms |
31864 KB |
Output is correct |
84 |
Correct |
105 ms |
31688 KB |
Output is correct |
85 |
Correct |
106 ms |
31756 KB |
Output is correct |
86 |
Correct |
117 ms |
31668 KB |
Output is correct |
87 |
Correct |
113 ms |
32176 KB |
Output is correct |
88 |
Correct |
106 ms |
31776 KB |
Output is correct |
89 |
Correct |
109 ms |
31700 KB |
Output is correct |
90 |
Correct |
64 ms |
20372 KB |
Output is correct |
91 |
Correct |
109 ms |
31772 KB |
Output is correct |
92 |
Correct |
110 ms |
31768 KB |
Output is correct |
93 |
Correct |
117 ms |
31684 KB |
Output is correct |
94 |
Correct |
111 ms |
31692 KB |
Output is correct |
95 |
Correct |
111 ms |
31756 KB |
Output is correct |
96 |
Correct |
105 ms |
31780 KB |
Output is correct |
97 |
Correct |
116 ms |
31752 KB |
Output is correct |
98 |
Correct |
108 ms |
31756 KB |
Output is correct |
99 |
Correct |
108 ms |
31752 KB |
Output is correct |
100 |
Correct |
112 ms |
31768 KB |
Output is correct |