#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MAXN = 2600;
int n, m;
char s[MAXN][MAXN];
int ans[MAXN];
int up[MAXN][MAXN];
int dw[MAXN][MAXN];
int main() {
// freopen("input.txt","r",stdin);
// freopen("bomb.out","w",stdout);
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i)
scanf(" %s", s[i]);
int mxh = n;
int mxw = m;
for (int i = 0; i < n; ++i) {
int cnt = 0;
for (int j = 0; j < m; ++j) {
if (s[i][j] == '1')
++cnt;
if (s[i][j] == '1' && (j == m - 1 || s[i][j + 1] == '0')) {
mxw = min(mxw, cnt);
cnt = 0;
}
}
}
for (int i = 0; i < m; ++i) {
int cnt = 0;
for (int j = 0; j < n; ++j) {
if (s[j][i] == '1')
++cnt, up[j][i] = cnt;
if (s[j][i] == '1' && (j == n - 1 || s[j + 1][i] == '0')) {
mxh = min(mxh, cnt);
cnt = 0;
}
}
}
for (int i = 0; i < m; ++i) {
int cnt = 0;
for (int j = n - 1; j >= 0; --j) {
if (s[j][i] == '1')
++cnt, dw[j][i] = cnt;
else
cnt = 0;
}
}
for (int i = 0; i <= mxw; ++i)
ans[i] = mxh;
for (int i = 0; i < n; ++i) {
int a = MAXN;
int b = MAXN;
int cnt = 0;
for (int j = 0; j < m; ++j) {
if (s[i][j] == '1') {
a = min(a, up[i][j]);
b = min(b, dw[i][j]);
++cnt;
ans[cnt] = min(ans[cnt], a + b - 1);
}
else {
a = MAXN;
b = MAXN;
cnt = 0;
}
}
}
for (int i = 0; i < n; ++i) {
int a = MAXN;
int b = MAXN;
int cnt = 0;
for (int j = m - 1; j >= 0; --j) {
if (s[i][j] == '1') {
a = min(a, up[i][j]);
b = min(b, dw[i][j]);
++cnt;
ans[cnt] = min(ans[cnt], a + b - 1);
}
else {
a = MAXN;
b = MAXN;
cnt = 0;
}
}
}
for (int i = 1; i <= mxw; ++i)
ans[i] = min(ans[i], ans[i - 1]);
int mh = 0;
int mw = 0;
for (int i = 1; i <= mxw; ++i)
if (mh * mw < i * ans[i])
mw = i, mh = ans[i];
cout << mh * mw << "\n";
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
bomb.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %s", s[i]);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
19 ms |
26920 KB |
Output is correct |
4 |
Correct |
22 ms |
26920 KB |
Output is correct |
5 |
Correct |
3 ms |
26920 KB |
Output is correct |
6 |
Correct |
2 ms |
26920 KB |
Output is correct |
7 |
Correct |
2 ms |
26920 KB |
Output is correct |
8 |
Correct |
2 ms |
26920 KB |
Output is correct |
9 |
Correct |
3 ms |
26920 KB |
Output is correct |
10 |
Correct |
2 ms |
26920 KB |
Output is correct |
11 |
Correct |
2 ms |
26920 KB |
Output is correct |
12 |
Correct |
2 ms |
26920 KB |
Output is correct |
13 |
Correct |
3 ms |
26920 KB |
Output is correct |
14 |
Correct |
3 ms |
26920 KB |
Output is correct |
15 |
Correct |
2 ms |
26920 KB |
Output is correct |
16 |
Correct |
2 ms |
26920 KB |
Output is correct |
17 |
Correct |
3 ms |
26920 KB |
Output is correct |
18 |
Correct |
2 ms |
26920 KB |
Output is correct |
19 |
Correct |
2 ms |
26920 KB |
Output is correct |
20 |
Correct |
3 ms |
26920 KB |
Output is correct |
21 |
Correct |
2 ms |
26920 KB |
Output is correct |
22 |
Correct |
3 ms |
26920 KB |
Output is correct |
23 |
Correct |
4 ms |
26920 KB |
Output is correct |
24 |
Correct |
3 ms |
26920 KB |
Output is correct |
25 |
Correct |
3 ms |
26920 KB |
Output is correct |
26 |
Correct |
3 ms |
26920 KB |
Output is correct |
27 |
Correct |
6 ms |
26920 KB |
Output is correct |
28 |
Correct |
4 ms |
26920 KB |
Output is correct |
29 |
Correct |
7 ms |
26920 KB |
Output is correct |
30 |
Correct |
7 ms |
26920 KB |
Output is correct |
31 |
Correct |
6 ms |
26920 KB |
Output is correct |
32 |
Correct |
6 ms |
26920 KB |
Output is correct |
33 |
Correct |
9 ms |
26920 KB |
Output is correct |
34 |
Correct |
4 ms |
26920 KB |
Output is correct |
35 |
Correct |
5 ms |
26920 KB |
Output is correct |
36 |
Correct |
10 ms |
26920 KB |
Output is correct |
37 |
Correct |
3 ms |
26920 KB |
Output is correct |
38 |
Correct |
353 ms |
65784 KB |
Output is correct |
39 |
Correct |
2 ms |
65784 KB |
Output is correct |
40 |
Correct |
31 ms |
65784 KB |
Output is correct |
41 |
Correct |
2 ms |
65784 KB |
Output is correct |
42 |
Correct |
3 ms |
65784 KB |
Output is correct |
43 |
Correct |
277 ms |
68060 KB |
Output is correct |
44 |
Correct |
8 ms |
68060 KB |
Output is correct |
45 |
Correct |
243 ms |
75136 KB |
Output is correct |
46 |
Correct |
233 ms |
84964 KB |
Output is correct |
47 |
Correct |
249 ms |
87364 KB |
Output is correct |
48 |
Correct |
225 ms |
97188 KB |
Output is correct |
49 |
Correct |
350 ms |
103416 KB |
Output is correct |
50 |
Correct |
309 ms |
109400 KB |
Output is correct |
51 |
Correct |
258 ms |
115500 KB |
Output is correct |
52 |
Correct |
231 ms |
121508 KB |
Output is correct |
53 |
Correct |
233 ms |
126980 KB |
Output is correct |
54 |
Correct |
182 ms |
126980 KB |
Output is correct |
55 |
Correct |
158 ms |
126980 KB |
Output is correct |
56 |
Correct |
360 ms |
146200 KB |
Output is correct |
57 |
Correct |
148 ms |
146200 KB |
Output is correct |
58 |
Correct |
163 ms |
146200 KB |
Output is correct |
59 |
Correct |
152 ms |
146200 KB |
Output is correct |
60 |
Correct |
217 ms |
162368 KB |
Output is correct |
61 |
Correct |
351 ms |
175620 KB |
Output is correct |
62 |
Correct |
352 ms |
175916 KB |
Output is correct |
63 |
Correct |
348 ms |
175916 KB |
Output is correct |
64 |
Correct |
156 ms |
175916 KB |
Output is correct |
65 |
Correct |
215 ms |
175916 KB |
Output is correct |
66 |
Correct |
233 ms |
175916 KB |
Output is correct |
67 |
Correct |
269 ms |
175916 KB |
Output is correct |
68 |
Correct |
282 ms |
175916 KB |
Output is correct |
69 |
Correct |
160 ms |
175916 KB |
Output is correct |
70 |
Correct |
77 ms |
175916 KB |
Output is correct |
71 |
Correct |
118 ms |
175916 KB |
Output is correct |
72 |
Correct |
132 ms |
175916 KB |
Output is correct |
73 |
Correct |
141 ms |
175916 KB |
Output is correct |
74 |
Correct |
137 ms |
175916 KB |
Output is correct |
75 |
Correct |
143 ms |
175916 KB |
Output is correct |
76 |
Correct |
145 ms |
175916 KB |
Output is correct |
77 |
Correct |
164 ms |
175916 KB |
Output is correct |
78 |
Correct |
148 ms |
175916 KB |
Output is correct |
79 |
Correct |
102 ms |
175916 KB |
Output is correct |
80 |
Correct |
79 ms |
175916 KB |
Output is correct |
81 |
Correct |
83 ms |
175916 KB |
Output is correct |
82 |
Correct |
190 ms |
175916 KB |
Output is correct |
83 |
Correct |
181 ms |
175916 KB |
Output is correct |
84 |
Correct |
90 ms |
175916 KB |
Output is correct |
85 |
Correct |
153 ms |
175916 KB |
Output is correct |
86 |
Correct |
349 ms |
175916 KB |
Output is correct |
87 |
Correct |
164 ms |
175916 KB |
Output is correct |
88 |
Correct |
171 ms |
175916 KB |
Output is correct |
89 |
Correct |
232 ms |
175916 KB |
Output is correct |
90 |
Correct |
83 ms |
175916 KB |
Output is correct |
91 |
Correct |
173 ms |
175916 KB |
Output is correct |
92 |
Correct |
231 ms |
175916 KB |
Output is correct |
93 |
Correct |
345 ms |
175916 KB |
Output is correct |
94 |
Correct |
307 ms |
175916 KB |
Output is correct |
95 |
Correct |
181 ms |
175916 KB |
Output is correct |
96 |
Correct |
173 ms |
175916 KB |
Output is correct |
97 |
Correct |
314 ms |
175916 KB |
Output is correct |
98 |
Correct |
170 ms |
175916 KB |
Output is correct |
99 |
Correct |
203 ms |
175916 KB |
Output is correct |
100 |
Correct |
384 ms |
175916 KB |
Output is correct |