#include <iostream>
using namespace std;
const int N = 2505;
int a[N][N], ans[N];
int L[N][N], R[N][N];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1 ; i <= n ; ++ i) {
for (int j = 1 ; j <= m ; ++ j) {
char c;
cin >> c;
a[i][j] = (c - '0');
}
}
for (int i = 1 ; i <= n ; ++ i) {
ans[i] = m;
}
int lim = n;
for (int rep = 0 ; rep < 2 ; ++ rep) {
for (int i = 1 ; i <= n ; ++ i) {
for (int j = 1 ; j <= m ; ++ j) {
if (a[i][j]) L[i][j] = L[i][j - 1] + 1;
else L[i][j] = 0;
}
for (int j = m ; j >= 1 ; -- j) {
if (a[i][j]) R[i][j] = R[i][j + 1] + 1;
else R[i][j] = 0;
}
for (int j = 1 ; j <= m ; ++ j) {
if (a[i][j]) ans[1] = min(ans[1], L[i][j] + R[i][j] - 1);
}
}
for (int j = 1 ; j <= m ; ++ j) {
int cnt = 0;
int LX = -1, RX = -1;
for (int i = 1 ; i <= n + 1 ; ++ i) {
if (a[i][j]) {
cnt++;
if (cnt == 1) {
LX = L[i][j], RX = R[i][j];
}
LX = min(LX, L[i][j]), RX = min(RX, R[i][j]);
ans[cnt] = min(ans[cnt], LX + RX - 1);
} else {
if (cnt > 0) lim = min(lim, cnt);
LX = RX = -1;
cnt = 0;
}
}
}
for (int i = 1 ; i <= n / 2 ; ++ i) {
for (int j = 1 ; j <= m ; ++ j) {
swap(a[i][j], a[n - i + 1][j]);
}
}
}
int res = 0;
for (int i = 1 ; i <= lim ; ++ i) {
//cerr << i << " " << ans[i] << endl;
ans[i + 1] = min(ans[i + 1], ans[i]);
res = max(res, ans[i] * i);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
13 ms |
45024 KB |
Output is correct |
4 |
Correct |
13 ms |
45088 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2496 KB |
Output is correct |
8 |
Correct |
1 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
2500 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4452 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
2 ms |
8900 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8644 KB |
Output is correct |
21 |
Correct |
2 ms |
10696 KB |
Output is correct |
22 |
Correct |
2 ms |
10588 KB |
Output is correct |
23 |
Correct |
2 ms |
8792 KB |
Output is correct |
24 |
Correct |
2 ms |
8796 KB |
Output is correct |
25 |
Correct |
2 ms |
7004 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
7 ms |
9560 KB |
Output is correct |
28 |
Correct |
9 ms |
14940 KB |
Output is correct |
29 |
Correct |
10 ms |
14428 KB |
Output is correct |
30 |
Correct |
14 ms |
14204 KB |
Output is correct |
31 |
Correct |
9 ms |
14172 KB |
Output is correct |
32 |
Correct |
9 ms |
14428 KB |
Output is correct |
33 |
Correct |
12 ms |
20580 KB |
Output is correct |
34 |
Correct |
6 ms |
16988 KB |
Output is correct |
35 |
Correct |
17 ms |
21340 KB |
Output is correct |
36 |
Correct |
20 ms |
14040 KB |
Output is correct |
37 |
Correct |
1 ms |
6488 KB |
Output is correct |
38 |
Correct |
440 ms |
77108 KB |
Output is correct |
39 |
Correct |
1 ms |
6492 KB |
Output is correct |
40 |
Correct |
49 ms |
27216 KB |
Output is correct |
41 |
Correct |
1 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
9052 KB |
Output is correct |
43 |
Correct |
395 ms |
77396 KB |
Output is correct |
44 |
Correct |
13 ms |
19548 KB |
Output is correct |
45 |
Correct |
391 ms |
77608 KB |
Output is correct |
46 |
Correct |
389 ms |
77256 KB |
Output is correct |
47 |
Correct |
393 ms |
77144 KB |
Output is correct |
48 |
Correct |
378 ms |
77392 KB |
Output is correct |
49 |
Correct |
473 ms |
77344 KB |
Output is correct |
50 |
Correct |
378 ms |
77396 KB |
Output is correct |
51 |
Correct |
379 ms |
77384 KB |
Output is correct |
52 |
Correct |
381 ms |
77396 KB |
Output is correct |
53 |
Correct |
383 ms |
77212 KB |
Output is correct |
54 |
Correct |
343 ms |
77396 KB |
Output is correct |
55 |
Correct |
331 ms |
77220 KB |
Output is correct |
56 |
Correct |
423 ms |
77396 KB |
Output is correct |
57 |
Correct |
331 ms |
77392 KB |
Output is correct |
58 |
Correct |
356 ms |
77508 KB |
Output is correct |
59 |
Correct |
330 ms |
77260 KB |
Output is correct |
60 |
Correct |
377 ms |
77232 KB |
Output is correct |
61 |
Correct |
437 ms |
77340 KB |
Output is correct |
62 |
Correct |
438 ms |
77508 KB |
Output is correct |
63 |
Correct |
442 ms |
77340 KB |
Output is correct |
64 |
Correct |
339 ms |
77268 KB |
Output is correct |
65 |
Correct |
366 ms |
77388 KB |
Output is correct |
66 |
Correct |
371 ms |
77224 KB |
Output is correct |
67 |
Correct |
404 ms |
77392 KB |
Output is correct |
68 |
Correct |
399 ms |
77328 KB |
Output is correct |
69 |
Correct |
339 ms |
77396 KB |
Output is correct |
70 |
Correct |
207 ms |
66976 KB |
Output is correct |
71 |
Correct |
307 ms |
77480 KB |
Output is correct |
72 |
Correct |
328 ms |
77396 KB |
Output is correct |
73 |
Correct |
331 ms |
77340 KB |
Output is correct |
74 |
Correct |
324 ms |
77140 KB |
Output is correct |
75 |
Correct |
335 ms |
77140 KB |
Output is correct |
76 |
Correct |
334 ms |
77136 KB |
Output is correct |
77 |
Correct |
343 ms |
77136 KB |
Output is correct |
78 |
Correct |
332 ms |
77140 KB |
Output is correct |
79 |
Correct |
293 ms |
77332 KB |
Output is correct |
80 |
Correct |
305 ms |
77220 KB |
Output is correct |
81 |
Correct |
306 ms |
77264 KB |
Output is correct |
82 |
Correct |
346 ms |
77332 KB |
Output is correct |
83 |
Correct |
342 ms |
77340 KB |
Output is correct |
84 |
Correct |
293 ms |
77140 KB |
Output is correct |
85 |
Correct |
330 ms |
77140 KB |
Output is correct |
86 |
Correct |
421 ms |
77136 KB |
Output is correct |
87 |
Correct |
338 ms |
77344 KB |
Output is correct |
88 |
Correct |
341 ms |
77280 KB |
Output is correct |
89 |
Correct |
357 ms |
77484 KB |
Output is correct |
90 |
Correct |
216 ms |
65576 KB |
Output is correct |
91 |
Correct |
349 ms |
77344 KB |
Output is correct |
92 |
Correct |
364 ms |
77136 KB |
Output is correct |
93 |
Correct |
421 ms |
77588 KB |
Output is correct |
94 |
Correct |
367 ms |
77356 KB |
Output is correct |
95 |
Correct |
334 ms |
77444 KB |
Output is correct |
96 |
Correct |
333 ms |
77140 KB |
Output is correct |
97 |
Correct |
422 ms |
77344 KB |
Output is correct |
98 |
Correct |
333 ms |
77136 KB |
Output is correct |
99 |
Correct |
356 ms |
77348 KB |
Output is correct |
100 |
Correct |
413 ms |
77348 KB |
Output is correct |