#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define PB push_back
using namespace std;
const int N = 2505;
int n, m;
char s[N][N];
int A[N][N], B[N][N];
int par[N], L[N], R[N], un[N], nula[N];
int S[N];
int pr(int x){
if(x == par[x]) return x;
return par[x] = pr(par[x]);
}
void mrg(int x, int y){
if(x < 0 || y >= m || !un[x] || !un[y]) return;
// printf("mrg %d %d\n", x, y);
x = pr(x), y = pr(y);
if(x == y) return;
if(nula[x]) S[R[x] - L[x] + 1]--;
if(nula[y]) S[R[y] - L[y] + 1]--;
if(R[x] - L[x] > R[y] - L[y]){
par[y] = x; R[x] = R[y];
nula[x] |= nula[y];
if(nula[x])
S[R[x] - L[x] + 1]++;
}
else{
par[x] = y; L[y] = L[x];
nula[y] |= nula[x];
if(nula[y])
S[R[y] - L[y] + 1]++;
}
}
vector < int > kon[N];
int ans[N];
void odradi_redak(int rd){
for(int i = 0;i <= m;i++) S[i] = 0;
for(int i = 0;i <= n;i++) kon[i].clear();
for(int i = 0;i < m;i++){
un[i] = 0;
if(s[rd][i] == '0') continue;
par[i] = i; nula[i] = (B[rd][i] == 1);
L[i] = i, R[i] = i;
kon[A[rd][i]].PB(i);
if(nula[i]) S[0]++;
}
if(!S[0]) return;
int cur = 0;
for(int i = n;i >= 1;i--){
for(int x : kon[i]){
if(nula[x])
S[0]--, S[1]++;
// printf("x = %d nula = %d\n", x, nula[x]);
un[x] = 1;
mrg(x - 1, x);
mrg(x, x + 1);
}
while(!S[cur]) cur++;
//printf("rd = %d i = %d cur = %d\n", rd, i, cur);
ans[i] = min(ans[i], cur);
}
}
int main(){
//freopen("bomb.in", "r", stdin);
//freopen("bomb.out", "w", stdout);
scanf("%d%d", &n, &m);
int fin = n * m;
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
scanf(" %c", &s[i][j]);
for(int bla = 0;bla < 2;bla++){
memset(A, 0, sizeof(A));
memset(B, 0, sizeof(B));
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
A[i][j] = (1 + (i ? A[i - 1][j] : 0)) * (s[i][j] - '0');
for(int i = n - 1;i >= 0;i--)
for(int j = 0;j < m;j++)
B[i][j] = (1 + B[i + 1][j]) * (s[i][j] - '0');
for(int i = 1;i <= n;i++) ans[i] = m;
for(int i = 0;i < n;i++) odradi_redak(i);
int sol = 1;
for(int i = 1;i <= n;i++){
sol = max(sol, ans[i] * i);
//printf("ans[ %d ] = %d\n", i, ans[i]);
}
fin = min(fin, sol);
for(int i = 0;n - i - 1 > i;i++){
for(int j = 0;j < m;j++)
swap(s[i][j], s[n - i - 1][j]);
}
}
printf("%d\n", fin);
return 0;
}
/*
5 6
000000
111110
111110
111110
001000
*/
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
79 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
bomb.cpp:83:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
83 | scanf(" %c", &s[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
49392 KB |
Output is correct |
2 |
Correct |
27 ms |
49428 KB |
Output is correct |
3 |
Correct |
43 ms |
55628 KB |
Output is correct |
4 |
Correct |
43 ms |
55616 KB |
Output is correct |
5 |
Correct |
27 ms |
49488 KB |
Output is correct |
6 |
Correct |
27 ms |
49508 KB |
Output is correct |
7 |
Incorrect |
27 ms |
49456 KB |
Output isn't correct |
8 |
Correct |
27 ms |
49504 KB |
Output is correct |
9 |
Incorrect |
27 ms |
49524 KB |
Output isn't correct |
10 |
Correct |
27 ms |
49516 KB |
Output is correct |
11 |
Correct |
28 ms |
49412 KB |
Output is correct |
12 |
Correct |
26 ms |
49488 KB |
Output is correct |
13 |
Correct |
27 ms |
49524 KB |
Output is correct |
14 |
Correct |
28 ms |
49420 KB |
Output is correct |
15 |
Correct |
27 ms |
49428 KB |
Output is correct |
16 |
Correct |
28 ms |
49456 KB |
Output is correct |
17 |
Correct |
28 ms |
49604 KB |
Output is correct |
18 |
Correct |
28 ms |
49664 KB |
Output is correct |
19 |
Incorrect |
28 ms |
49692 KB |
Output isn't correct |
20 |
Correct |
28 ms |
49716 KB |
Output is correct |
21 |
Correct |
29 ms |
49612 KB |
Output is correct |
22 |
Correct |
29 ms |
49680 KB |
Output is correct |
23 |
Incorrect |
29 ms |
49740 KB |
Output isn't correct |
24 |
Incorrect |
29 ms |
49692 KB |
Output isn't correct |
25 |
Correct |
28 ms |
49740 KB |
Output is correct |
26 |
Incorrect |
29 ms |
49740 KB |
Output isn't correct |
27 |
Incorrect |
38 ms |
50460 KB |
Output isn't correct |
28 |
Correct |
41 ms |
50200 KB |
Output is correct |
29 |
Correct |
41 ms |
50652 KB |
Output is correct |
30 |
Incorrect |
50 ms |
50628 KB |
Output isn't correct |
31 |
Correct |
39 ms |
50324 KB |
Output is correct |
32 |
Incorrect |
47 ms |
50492 KB |
Output isn't correct |
33 |
Correct |
47 ms |
50736 KB |
Output is correct |
34 |
Correct |
34 ms |
50288 KB |
Output is correct |
35 |
Incorrect |
43 ms |
50500 KB |
Output isn't correct |
36 |
Incorrect |
47 ms |
51440 KB |
Output isn't correct |
37 |
Correct |
28 ms |
49452 KB |
Output is correct |
38 |
Correct |
597 ms |
90316 KB |
Output is correct |
39 |
Correct |
28 ms |
49484 KB |
Output is correct |
40 |
Correct |
99 ms |
54092 KB |
Output is correct |
41 |
Correct |
27 ms |
49544 KB |
Output is correct |
42 |
Correct |
29 ms |
49752 KB |
Output is correct |
43 |
Correct |
635 ms |
60692 KB |
Output is correct |
44 |
Correct |
47 ms |
50972 KB |
Output is correct |
45 |
Correct |
592 ms |
70128 KB |
Output is correct |
46 |
Correct |
532 ms |
55844 KB |
Output is correct |
47 |
Correct |
587 ms |
70344 KB |
Output is correct |
48 |
Correct |
631 ms |
65872 KB |
Output is correct |
49 |
Incorrect |
629 ms |
89440 KB |
Output isn't correct |
50 |
Correct |
587 ms |
66988 KB |
Output is correct |
51 |
Correct |
576 ms |
66648 KB |
Output is correct |
52 |
Correct |
576 ms |
66280 KB |
Output is correct |
53 |
Correct |
606 ms |
65732 KB |
Output is correct |
54 |
Correct |
544 ms |
65680 KB |
Output is correct |
55 |
Correct |
566 ms |
65720 KB |
Output is correct |
56 |
Correct |
600 ms |
89772 KB |
Output is correct |
57 |
Correct |
558 ms |
65956 KB |
Output is correct |
58 |
Correct |
530 ms |
66240 KB |
Output is correct |
59 |
Correct |
520 ms |
65732 KB |
Output is correct |
60 |
Correct |
633 ms |
72996 KB |
Output is correct |
61 |
Incorrect |
612 ms |
89548 KB |
Output isn't correct |
62 |
Incorrect |
601 ms |
85996 KB |
Output isn't correct |
63 |
Incorrect |
602 ms |
90248 KB |
Output isn't correct |
64 |
Correct |
516 ms |
63620 KB |
Output is correct |
65 |
Correct |
565 ms |
65732 KB |
Output is correct |
66 |
Correct |
604 ms |
66116 KB |
Output is correct |
67 |
Correct |
590 ms |
68168 KB |
Output is correct |
68 |
Correct |
607 ms |
70716 KB |
Output is correct |
69 |
Correct |
514 ms |
66092 KB |
Output is correct |
70 |
Incorrect |
326 ms |
55400 KB |
Output isn't correct |
71 |
Incorrect |
502 ms |
58264 KB |
Output isn't correct |
72 |
Correct |
513 ms |
58876 KB |
Output is correct |
73 |
Correct |
533 ms |
58508 KB |
Output is correct |
74 |
Incorrect |
510 ms |
58528 KB |
Output isn't correct |
75 |
Incorrect |
520 ms |
59980 KB |
Output isn't correct |
76 |
Correct |
539 ms |
58980 KB |
Output is correct |
77 |
Correct |
505 ms |
59616 KB |
Output is correct |
78 |
Correct |
523 ms |
59052 KB |
Output is correct |
79 |
Incorrect |
481 ms |
55752 KB |
Output isn't correct |
80 |
Incorrect |
495 ms |
55660 KB |
Output isn't correct |
81 |
Incorrect |
528 ms |
56168 KB |
Output isn't correct |
82 |
Correct |
557 ms |
59804 KB |
Output is correct |
83 |
Incorrect |
546 ms |
58976 KB |
Output isn't correct |
84 |
Incorrect |
508 ms |
55648 KB |
Output isn't correct |
85 |
Incorrect |
533 ms |
59904 KB |
Output isn't correct |
86 |
Incorrect |
593 ms |
86980 KB |
Output isn't correct |
87 |
Correct |
554 ms |
61200 KB |
Output is correct |
88 |
Correct |
558 ms |
59376 KB |
Output is correct |
89 |
Correct |
575 ms |
69908 KB |
Output is correct |
90 |
Incorrect |
350 ms |
57108 KB |
Output isn't correct |
91 |
Correct |
547 ms |
65920 KB |
Output is correct |
92 |
Correct |
538 ms |
67244 KB |
Output is correct |
93 |
Correct |
589 ms |
86200 KB |
Output is correct |
94 |
Correct |
553 ms |
69060 KB |
Output is correct |
95 |
Incorrect |
545 ms |
59468 KB |
Output isn't correct |
96 |
Correct |
512 ms |
59004 KB |
Output is correct |
97 |
Correct |
594 ms |
87024 KB |
Output is correct |
98 |
Correct |
516 ms |
60640 KB |
Output is correct |
99 |
Incorrect |
537 ms |
68676 KB |
Output isn't correct |
100 |
Incorrect |
583 ms |
85584 KB |
Output isn't correct |