#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];
}
vector<int> res(n, INF);
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:38:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while (k < n && k - i < res.size() && g[k][j] == '1')
| ~~~~~~^~~~~~~~~~~~
bomb.cpp: In function 'int main()':
bomb.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i = 0; i < res.size(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
460 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
460 KB |
Output isn't correct |
27 |
Incorrect |
2 ms |
924 KB |
Output isn't correct |
28 |
Correct |
2 ms |
1112 KB |
Output is correct |
29 |
Correct |
2 ms |
1132 KB |
Output is correct |
30 |
Correct |
3 ms |
1600 KB |
Output is correct |
31 |
Correct |
3 ms |
1368 KB |
Output is correct |
32 |
Correct |
3 ms |
1404 KB |
Output is correct |
33 |
Correct |
4 ms |
1648 KB |
Output is correct |
34 |
Correct |
2 ms |
920 KB |
Output is correct |
35 |
Correct |
3 ms |
1632 KB |
Output is correct |
36 |
Incorrect |
4 ms |
1636 KB |
Output isn't correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
112 ms |
35068 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Incorrect |
13 ms |
4852 KB |
Output isn't correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
129 ms |
35048 KB |
Output is correct |
44 |
Correct |
4 ms |
1632 KB |
Output is correct |
45 |
Correct |
113 ms |
35412 KB |
Output is correct |
46 |
Correct |
125 ms |
35076 KB |
Output is correct |
47 |
Correct |
114 ms |
35100 KB |
Output is correct |
48 |
Correct |
105 ms |
35336 KB |
Output is correct |
49 |
Incorrect |
122 ms |
35508 KB |
Output isn't correct |
50 |
Correct |
110 ms |
35100 KB |
Output is correct |
51 |
Correct |
104 ms |
35072 KB |
Output is correct |
52 |
Correct |
113 ms |
35140 KB |
Output is correct |
53 |
Correct |
105 ms |
35112 KB |
Output is correct |
54 |
Correct |
108 ms |
35148 KB |
Output is correct |
55 |
Correct |
103 ms |
35148 KB |
Output is correct |
56 |
Correct |
141 ms |
35096 KB |
Output is correct |
57 |
Correct |
104 ms |
35060 KB |
Output is correct |
58 |
Correct |
100 ms |
35096 KB |
Output is correct |
59 |
Correct |
101 ms |
35072 KB |
Output is correct |
60 |
Incorrect |
144 ms |
35060 KB |
Output isn't correct |
61 |
Incorrect |
117 ms |
35100 KB |
Output isn't correct |
62 |
Incorrect |
118 ms |
35116 KB |
Output isn't correct |
63 |
Incorrect |
121 ms |
35100 KB |
Output isn't correct |
64 |
Incorrect |
105 ms |
35008 KB |
Output isn't correct |
65 |
Correct |
106 ms |
35040 KB |
Output is correct |
66 |
Correct |
108 ms |
35092 KB |
Output is correct |
67 |
Correct |
106 ms |
35112 KB |
Output is correct |
68 |
Correct |
125 ms |
35104 KB |
Output is correct |
69 |
Correct |
110 ms |
35360 KB |
Output is correct |
70 |
Correct |
62 ms |
22672 KB |
Output is correct |
71 |
Correct |
101 ms |
35100 KB |
Output is correct |
72 |
Correct |
122 ms |
35068 KB |
Output is correct |
73 |
Correct |
105 ms |
35232 KB |
Output is correct |
74 |
Correct |
107 ms |
35100 KB |
Output is correct |
75 |
Correct |
101 ms |
35096 KB |
Output is correct |
76 |
Correct |
106 ms |
35044 KB |
Output is correct |
77 |
Correct |
101 ms |
35112 KB |
Output is correct |
78 |
Correct |
104 ms |
35040 KB |
Output is correct |
79 |
Correct |
102 ms |
35060 KB |
Output is correct |
80 |
Correct |
110 ms |
35064 KB |
Output is correct |
81 |
Correct |
102 ms |
35088 KB |
Output is correct |
82 |
Correct |
105 ms |
35156 KB |
Output is correct |
83 |
Correct |
108 ms |
35080 KB |
Output is correct |
84 |
Correct |
102 ms |
35112 KB |
Output is correct |
85 |
Correct |
101 ms |
35088 KB |
Output is correct |
86 |
Correct |
119 ms |
35064 KB |
Output is correct |
87 |
Correct |
104 ms |
35148 KB |
Output is correct |
88 |
Correct |
110 ms |
35204 KB |
Output is correct |
89 |
Correct |
108 ms |
35008 KB |
Output is correct |
90 |
Correct |
65 ms |
22800 KB |
Output is correct |
91 |
Correct |
106 ms |
35064 KB |
Output is correct |
92 |
Correct |
105 ms |
35100 KB |
Output is correct |
93 |
Correct |
111 ms |
35060 KB |
Output is correct |
94 |
Correct |
101 ms |
35248 KB |
Output is correct |
95 |
Correct |
127 ms |
35064 KB |
Output is correct |
96 |
Correct |
107 ms |
35100 KB |
Output is correct |
97 |
Correct |
110 ms |
31768 KB |
Output is correct |
98 |
Correct |
117 ms |
32024 KB |
Output is correct |
99 |
Correct |
103 ms |
31724 KB |
Output is correct |
100 |
Correct |
108 ms |
31868 KB |
Output is correct |