#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;
{
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 (rr[i][j] - j > 0)
{
xx = min(xx, rr[i][j] - j);
}
}
}
for (int j = 0; j < m; j++)
{
int cur = n;
for (int i = n - 1; i >= 0; i--)
{
if (g[i][j] == '0')
{
cur = i;
}
rr[i][j] = cur;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (rr[i][j] - i > 0)
{
yy = min(yy, rr[i][j] - i);
}
}
}
}
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 (rr[i][j] - j > 0)
{
res[0] = min(res[0], rr[i][j] - j);
}
}
}
for (int i = 1; i < res.size(); i++)
{
res[i] = min(res[i], res[i - 1]);
}
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:89:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for (int i = 1; i < res.size(); i++)
| ~~^~~~~~~~~~~~
bomb.cpp:100:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | while (k < n && k - i < res.size() && g[k][j] == '1')
| ~~~~~~^~~~~~~~~~~~
bomb.cpp: In function 'int main()':
bomb.cpp:122:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for (int i = 0; i < res.size(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
1176 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
1112 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
1128 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
1560 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
1276 KB |
Output isn't correct |
32 |
Incorrect |
4 ms |
1420 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
1688 KB |
Output isn't correct |
34 |
Incorrect |
2 ms |
1176 KB |
Output isn't correct |
35 |
Incorrect |
5 ms |
1636 KB |
Output isn't correct |
36 |
Incorrect |
5 ms |
1636 KB |
Output isn't correct |
37 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
38 |
Incorrect |
285 ms |
37052 KB |
Output isn't correct |
39 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
40 |
Incorrect |
19 ms |
5108 KB |
Output isn't correct |
41 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
42 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
43 |
Incorrect |
260 ms |
36852 KB |
Output isn't correct |
44 |
Incorrect |
5 ms |
1636 KB |
Output isn't correct |
45 |
Incorrect |
247 ms |
36916 KB |
Output isn't correct |
46 |
Incorrect |
267 ms |
36852 KB |
Output isn't correct |
47 |
Incorrect |
249 ms |
36848 KB |
Output isn't correct |
48 |
Incorrect |
239 ms |
36840 KB |
Output isn't correct |
49 |
Incorrect |
251 ms |
36848 KB |
Output isn't correct |
50 |
Incorrect |
229 ms |
36840 KB |
Output isn't correct |
51 |
Incorrect |
246 ms |
36840 KB |
Output isn't correct |
52 |
Incorrect |
230 ms |
36888 KB |
Output isn't correct |
53 |
Incorrect |
246 ms |
36888 KB |
Output isn't correct |
54 |
Incorrect |
227 ms |
36944 KB |
Output isn't correct |
55 |
Incorrect |
223 ms |
36840 KB |
Output isn't correct |
56 |
Incorrect |
279 ms |
36968 KB |
Output isn't correct |
57 |
Incorrect |
217 ms |
36848 KB |
Output isn't correct |
58 |
Incorrect |
220 ms |
36796 KB |
Output isn't correct |
59 |
Incorrect |
223 ms |
36948 KB |
Output isn't correct |
60 |
Incorrect |
217 ms |
36848 KB |
Output isn't correct |
61 |
Incorrect |
263 ms |
37012 KB |
Output isn't correct |
62 |
Incorrect |
245 ms |
36840 KB |
Output isn't correct |
63 |
Incorrect |
249 ms |
36876 KB |
Output isn't correct |
64 |
Incorrect |
213 ms |
36844 KB |
Output isn't correct |
65 |
Incorrect |
237 ms |
36844 KB |
Output isn't correct |
66 |
Incorrect |
234 ms |
37288 KB |
Output isn't correct |
67 |
Incorrect |
237 ms |
36876 KB |
Output isn't correct |
68 |
Incorrect |
226 ms |
36876 KB |
Output isn't correct |
69 |
Incorrect |
228 ms |
37088 KB |
Output isn't correct |
70 |
Incorrect |
135 ms |
24064 KB |
Output isn't correct |
71 |
Incorrect |
216 ms |
36832 KB |
Output isn't correct |
72 |
Incorrect |
213 ms |
36884 KB |
Output isn't correct |
73 |
Incorrect |
214 ms |
36864 KB |
Output isn't correct |
74 |
Incorrect |
221 ms |
37120 KB |
Output isn't correct |
75 |
Incorrect |
211 ms |
36876 KB |
Output isn't correct |
76 |
Incorrect |
211 ms |
36892 KB |
Output isn't correct |
77 |
Incorrect |
224 ms |
36844 KB |
Output isn't correct |
78 |
Incorrect |
215 ms |
36888 KB |
Output isn't correct |
79 |
Incorrect |
202 ms |
36844 KB |
Output isn't correct |
80 |
Incorrect |
203 ms |
36848 KB |
Output isn't correct |
81 |
Incorrect |
204 ms |
37060 KB |
Output isn't correct |
82 |
Incorrect |
221 ms |
36912 KB |
Output isn't correct |
83 |
Incorrect |
217 ms |
36872 KB |
Output isn't correct |
84 |
Incorrect |
196 ms |
37008 KB |
Output isn't correct |
85 |
Incorrect |
210 ms |
36812 KB |
Output isn't correct |
86 |
Incorrect |
255 ms |
36876 KB |
Output isn't correct |
87 |
Incorrect |
216 ms |
36980 KB |
Output isn't correct |
88 |
Incorrect |
210 ms |
36872 KB |
Output isn't correct |
89 |
Incorrect |
225 ms |
36984 KB |
Output isn't correct |
90 |
Incorrect |
119 ms |
24040 KB |
Output isn't correct |
91 |
Incorrect |
216 ms |
36892 KB |
Output isn't correct |
92 |
Incorrect |
219 ms |
36848 KB |
Output isn't correct |
93 |
Incorrect |
244 ms |
36788 KB |
Output isn't correct |
94 |
Incorrect |
210 ms |
36816 KB |
Output isn't correct |
95 |
Incorrect |
215 ms |
36844 KB |
Output isn't correct |
96 |
Incorrect |
209 ms |
36876 KB |
Output isn't correct |
97 |
Incorrect |
266 ms |
36628 KB |
Output isn't correct |
98 |
Incorrect |
213 ms |
36616 KB |
Output isn't correct |
99 |
Incorrect |
227 ms |
36620 KB |
Output isn't correct |
100 |
Incorrect |
227 ms |
36604 KB |
Output isn't correct |