#include <bits/stdc++.h>
using namespace std;
#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");
const int nmax = 2500 + 5;
const int inf = 1 << 30;
int n, m;
int v[nmax + 1][nmax + 1];
int u[nmax + 1][nmax + 1];
int w[nmax + 1];
int st[nmax + 1][nmax + 1], dr[nmax + 1][nmax + 1];
string s[nmax + 1];
void check (int h, int w) {
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
v[i][j] = v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1] + (s[i][j - 1] - '0');
}
}
bool ok = 1;
for (int i = 1; i <= n - h + 1; ++ i) {
for (int j = 1; j <= m - w + 1; ++ j) {
int sum = v[i + h - 1][j + w - 1] - v[i - 1][j + w - 1] - v[i + h - 1][j - 1] + v[i - 1][j - 1];
if (sum == h * w) {
++ u[i][j];
++ u[i + h][j + w];
-- u[i + h][j];
-- u[i][j + w];
}
}
}
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
u[i][j] += u[i - 1][j] + u[i][j - 1] - u[i - 1][j - 1];
if ((u[i][j] == 0) != ((s[i][j - 1] - '0') == 0)) {
assert(0);
}
}
}
}
int main() {
fin.sync_with_stdio(false); fin.tie(); fout.tie();
fin >> n >> m;
for (int i = 1; i <= n; ++ i)
fin >> s[i];
for (int i = 1; i <= n; ++ i) {
s[i] = '0' + s[i] + '0';
}
s[0].resize(m + 2, '0');
s[n + 1].resize(m + 2, '0');
for (int i = 1; i <= n; ++ i) {
st[i][0] = 1;
for (int j = 1; j <= m; ++ j) {
if (s[i][j] == '1')
st[i][j] = st[i][j - 1];
else
st[i][j] = j + 1;
}
dr[i][m + 1] = m;
for (int j = m; j > 0; -- j) {
if (s[i][j] == '1')
dr[i][j] = dr[i][j + 1];
else
dr[i][j] = j - 1;
}
}
for (int i = 1; i <= n; ++ i)
w[i] = inf;
for (int i = 1; i <= n; ++ i) {
for (int j = 1; j <= m; ++ j) {
if (s[i - 1][j] == '0' && s[i][j] == '1') {
int k = i;
int mn = st[i][j], mx = dr[i][j];
while (k <= m && s[k][j] == '1') {
mn = max(mn, st[k][j]);
mx = min(mx, dr[k][j]);
w[k - i + 1] = min(w[k - i + 1], mx - mn + 1);
++ k;
}
}
}
for (int j = 1; j <= m; ++ j) {
if (s[i + 1][j] == '0' && s[i][j] == '1') {
int k = i;
int mn = st[i][j], mx = dr[i][j];
while (k > 0 && s[k][j] == '1') {
mn = max(mn, st[k][j]);
mx = min(mx, dr[k][j]);
w[i - k + 1] = min(w[i - k + 1], mx - mn + 1);
-- k;
}
}
}
}
int h = inf;
for (int j = 1; j <= m; ++ j) {
int cnt = 0;
for (int i = 1; i <= n; ++ i) {
if (s[i][j] == '1')
++ cnt;
else
cnt = 0;
if (s[i][j] == '1' && s[i + 1][j] == '0')
h = min(h, cnt);
}
}
int _w = inf;
for (int i = 1; i <= n; ++ i) {
int cnt = 0;
for (int j = 1; j <= m; ++ j) {
if (s[i][j] == '1')
++ cnt;
else
cnt = 0;
if (s[i][j] == '1' && s[i][j + 1] == '0')
_w = min(_w, cnt);
}
}
int amax = 0;
for (int i = 1; i <= h; ++ i) {
if (w[i] != inf)
amax = max(amax, i * min(w[i], _w));
}
cout << amax << "\n";
return 0;
}
Compilation message
bomb.cpp: In function 'void check(int, int)':
bomb.cpp:27:10: warning: unused variable 'ok' [-Wunused-variable]
bool ok = 1;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
18 ms |
20608 KB |
Output is correct |
4 |
Correct |
17 ms |
20580 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
512 KB |
Output is correct |
17 |
Correct |
3 ms |
1024 KB |
Output is correct |
18 |
Correct |
3 ms |
1024 KB |
Output is correct |
19 |
Correct |
3 ms |
1280 KB |
Output is correct |
20 |
Correct |
3 ms |
1280 KB |
Output is correct |
21 |
Correct |
2 ms |
896 KB |
Output is correct |
22 |
Correct |
3 ms |
1152 KB |
Output is correct |
23 |
Correct |
3 ms |
1280 KB |
Output is correct |
24 |
Correct |
3 ms |
1152 KB |
Output is correct |
25 |
Correct |
3 ms |
1408 KB |
Output is correct |
26 |
Correct |
17 ms |
1280 KB |
Output is correct |
27 |
Correct |
24 ms |
3676 KB |
Output is correct |
28 |
Correct |
8 ms |
3968 KB |
Output is correct |
29 |
Correct |
11 ms |
4992 KB |
Output is correct |
30 |
Correct |
8 ms |
5888 KB |
Output is correct |
31 |
Correct |
7 ms |
4736 KB |
Output is correct |
32 |
Correct |
7 ms |
5376 KB |
Output is correct |
33 |
Correct |
9 ms |
6272 KB |
Output is correct |
34 |
Correct |
6 ms |
4096 KB |
Output is correct |
35 |
Correct |
9 ms |
6272 KB |
Output is correct |
36 |
Correct |
12 ms |
6272 KB |
Output is correct |
37 |
Correct |
2 ms |
640 KB |
Output is correct |
38 |
Correct |
551 ms |
62584 KB |
Output is correct |
39 |
Correct |
2 ms |
640 KB |
Output is correct |
40 |
Correct |
39 ms |
15744 KB |
Output is correct |
41 |
Correct |
2 ms |
640 KB |
Output is correct |
42 |
Correct |
3 ms |
1408 KB |
Output is correct |
43 |
Correct |
397 ms |
62584 KB |
Output is correct |
44 |
Correct |
10 ms |
6272 KB |
Output is correct |
45 |
Correct |
390 ms |
62716 KB |
Output is correct |
46 |
Correct |
212 ms |
62584 KB |
Output is correct |
47 |
Correct |
402 ms |
62712 KB |
Output is correct |
48 |
Correct |
378 ms |
62660 KB |
Output is correct |
49 |
Correct |
588 ms |
62456 KB |
Output is correct |
50 |
Correct |
359 ms |
62584 KB |
Output is correct |
51 |
Correct |
364 ms |
62604 KB |
Output is correct |
52 |
Correct |
344 ms |
62456 KB |
Output is correct |
53 |
Correct |
371 ms |
62584 KB |
Output is correct |
54 |
Correct |
246 ms |
62584 KB |
Output is correct |
55 |
Correct |
255 ms |
62584 KB |
Output is correct |
56 |
Correct |
544 ms |
62712 KB |
Output is correct |
57 |
Correct |
251 ms |
62584 KB |
Output is correct |
58 |
Correct |
244 ms |
62584 KB |
Output is correct |
59 |
Correct |
229 ms |
62584 KB |
Output is correct |
60 |
Correct |
355 ms |
62584 KB |
Output is correct |
61 |
Correct |
565 ms |
62712 KB |
Output is correct |
62 |
Correct |
603 ms |
62584 KB |
Output is correct |
63 |
Correct |
572 ms |
62556 KB |
Output is correct |
64 |
Correct |
220 ms |
62456 KB |
Output is correct |
65 |
Correct |
338 ms |
62584 KB |
Output is correct |
66 |
Correct |
371 ms |
62456 KB |
Output is correct |
67 |
Correct |
422 ms |
62456 KB |
Output is correct |
68 |
Correct |
402 ms |
62456 KB |
Output is correct |
69 |
Correct |
231 ms |
62456 KB |
Output is correct |
70 |
Correct |
90 ms |
48120 KB |
Output is correct |
71 |
Correct |
190 ms |
62360 KB |
Output is correct |
72 |
Correct |
208 ms |
62328 KB |
Output is correct |
73 |
Correct |
208 ms |
62336 KB |
Output is correct |
74 |
Correct |
214 ms |
62328 KB |
Output is correct |
75 |
Correct |
216 ms |
62328 KB |
Output is correct |
76 |
Correct |
216 ms |
62328 KB |
Output is correct |
77 |
Correct |
239 ms |
62328 KB |
Output is correct |
78 |
Correct |
224 ms |
62328 KB |
Output is correct |
79 |
Correct |
125 ms |
62328 KB |
Output is correct |
80 |
Correct |
133 ms |
62456 KB |
Output is correct |
81 |
Correct |
133 ms |
62448 KB |
Output is correct |
82 |
Correct |
244 ms |
62328 KB |
Output is correct |
83 |
Correct |
258 ms |
62196 KB |
Output is correct |
84 |
Correct |
128 ms |
62072 KB |
Output is correct |
85 |
Correct |
231 ms |
62188 KB |
Output is correct |
86 |
Correct |
546 ms |
62200 KB |
Output is correct |
87 |
Correct |
227 ms |
62200 KB |
Output is correct |
88 |
Correct |
248 ms |
62200 KB |
Output is correct |
89 |
Correct |
347 ms |
62200 KB |
Output is correct |
90 |
Correct |
127 ms |
48008 KB |
Output is correct |
91 |
Correct |
297 ms |
62172 KB |
Output is correct |
92 |
Correct |
329 ms |
62072 KB |
Output is correct |
93 |
Correct |
528 ms |
62072 KB |
Output is correct |
94 |
Correct |
359 ms |
62072 KB |
Output is correct |
95 |
Correct |
248 ms |
61944 KB |
Output is correct |
96 |
Correct |
283 ms |
62072 KB |
Output is correct |
97 |
Correct |
544 ms |
62072 KB |
Output is correct |
98 |
Correct |
249 ms |
62072 KB |
Output is correct |
99 |
Correct |
347 ms |
62072 KB |
Output is correct |
100 |
Correct |
514 ms |
62072 KB |
Output is correct |