#include<bits/stdc++.h>
using namespace std;
template<class T>void umin(T& a,T b){if(b<a)a=b;}
template<class T>void umax(T& a,T b){if(b>a)a=b;}
int n,m,xx,yy,up[2505][2505],down[2505][2505],ans[2505];
bool ar[2505][2505];
char rd(){
char ch;
do{
scanf("%c",&ch);
}while(ch!='0'&&ch!='1');
return ch;
}
int main(){
scanf("%d%d",&n,&m);
xx=n,yy=m;
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=1;j<=m;j++){
ar[i][j]=(rd()=='1');
if(ar[i][j])cnt++;
else{
if(cnt)umin(yy,cnt);
cnt=0;
}
}
if(cnt)umin(yy,cnt);
}
for(int j=1;j<=m;j++){
int cnt=0;
for(int i=1;i<=n;i++){
if(ar[i][j]){
cnt++;
up[i][j]=up[i-1][j]+1;
}else{
if(cnt)umin(xx,cnt);
cnt=0;
}
}
if(cnt)umin(xx,cnt);
for(int i=n;i>0;i--)if(ar[i][j])down[i][j]=down[i+1][j]+1;
}
for(int i=1;i<=yy;i++)ans[i]=xx;
for(int i=1;i<=n;i++){
int cnt=0;
int a=2e9,b=2e9;
for(int j=1;j<=m;j++){
if(ar[i][j]){
umin(a,up[i][j]);
umin(b,down[i][j]);
umin(ans[++cnt],a+b-1);
}else{
cnt=0;
a=b=2e9;
}
}
cnt=0;
a=2e9,b=2e9;
for(int j=m;j>0;j--){
if(ar[i][j]){
umin(a,up[i][j]);
umin(b,down[i][j]);
umin(ans[++cnt],a+b-1);
}else{
cnt=0;
a=b=2e9;
}
}
}
int res=ans[1];
for(int i=2;i<=yy;i++){
umin(ans[i],ans[i-1]);
umax(res,i*ans[i]);
}
printf("%d",res);
}
Compilation message
bomb.cpp: In function 'char rd()':
bomb.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | scanf("%c",&ch);
| ~~~~~^~~~~~~~~~
bomb.cpp: In function 'int main()':
bomb.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
15 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
14 ms |
26476 KB |
Output is correct |
4 |
Correct |
14 ms |
26476 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
1004 KB |
Output is correct |
18 |
Correct |
1 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
1004 KB |
Output is correct |
20 |
Correct |
1 ms |
1004 KB |
Output is correct |
21 |
Correct |
1 ms |
620 KB |
Output is correct |
22 |
Correct |
1 ms |
876 KB |
Output is correct |
23 |
Correct |
2 ms |
1132 KB |
Output is correct |
24 |
Correct |
1 ms |
1004 KB |
Output is correct |
25 |
Correct |
2 ms |
1388 KB |
Output is correct |
26 |
Correct |
2 ms |
1516 KB |
Output is correct |
27 |
Correct |
7 ms |
4076 KB |
Output is correct |
28 |
Correct |
7 ms |
1516 KB |
Output is correct |
29 |
Correct |
10 ms |
5100 KB |
Output is correct |
30 |
Correct |
12 ms |
4204 KB |
Output is correct |
31 |
Correct |
10 ms |
3108 KB |
Output is correct |
32 |
Correct |
11 ms |
4076 KB |
Output is correct |
33 |
Correct |
19 ms |
5248 KB |
Output is correct |
34 |
Correct |
6 ms |
1772 KB |
Output is correct |
35 |
Correct |
13 ms |
2028 KB |
Output is correct |
36 |
Correct |
23 ms |
6636 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
547 ms |
55532 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
82 ms |
15596 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
2 ms |
1388 KB |
Output is correct |
43 |
Correct |
491 ms |
51560 KB |
Output is correct |
44 |
Correct |
22 ms |
5996 KB |
Output is correct |
45 |
Correct |
695 ms |
52988 KB |
Output is correct |
46 |
Correct |
596 ms |
55532 KB |
Output is correct |
47 |
Correct |
515 ms |
52960 KB |
Output is correct |
48 |
Correct |
479 ms |
55504 KB |
Output is correct |
49 |
Correct |
543 ms |
55532 KB |
Output is correct |
50 |
Correct |
473 ms |
55532 KB |
Output is correct |
51 |
Correct |
476 ms |
55532 KB |
Output is correct |
52 |
Correct |
459 ms |
55404 KB |
Output is correct |
53 |
Correct |
464 ms |
54856 KB |
Output is correct |
54 |
Correct |
446 ms |
42220 KB |
Output is correct |
55 |
Correct |
427 ms |
40428 KB |
Output is correct |
56 |
Correct |
525 ms |
55648 KB |
Output is correct |
57 |
Correct |
462 ms |
35484 KB |
Output is correct |
58 |
Correct |
598 ms |
40524 KB |
Output is correct |
59 |
Correct |
495 ms |
37440 KB |
Output is correct |
60 |
Correct |
455 ms |
47308 KB |
Output is correct |
61 |
Correct |
721 ms |
55532 KB |
Output is correct |
62 |
Correct |
573 ms |
55532 KB |
Output is correct |
63 |
Correct |
592 ms |
55484 KB |
Output is correct |
64 |
Correct |
685 ms |
38320 KB |
Output is correct |
65 |
Correct |
452 ms |
54380 KB |
Output is correct |
66 |
Correct |
692 ms |
51308 KB |
Output is correct |
67 |
Correct |
476 ms |
55532 KB |
Output is correct |
68 |
Correct |
652 ms |
55532 KB |
Output is correct |
69 |
Correct |
639 ms |
35104 KB |
Output is correct |
70 |
Correct |
250 ms |
15212 KB |
Output is correct |
71 |
Correct |
456 ms |
28132 KB |
Output is correct |
72 |
Correct |
539 ms |
33644 KB |
Output is correct |
73 |
Correct |
415 ms |
34028 KB |
Output is correct |
74 |
Correct |
423 ms |
35564 KB |
Output is correct |
75 |
Correct |
648 ms |
37228 KB |
Output is correct |
76 |
Correct |
423 ms |
38508 KB |
Output is correct |
77 |
Correct |
449 ms |
39020 KB |
Output is correct |
78 |
Correct |
420 ms |
39264 KB |
Output is correct |
79 |
Correct |
380 ms |
11756 KB |
Output is correct |
80 |
Correct |
361 ms |
13036 KB |
Output is correct |
81 |
Correct |
380 ms |
13412 KB |
Output is correct |
82 |
Correct |
443 ms |
41836 KB |
Output is correct |
83 |
Correct |
444 ms |
41964 KB |
Output is correct |
84 |
Correct |
360 ms |
7148 KB |
Output is correct |
85 |
Correct |
437 ms |
40812 KB |
Output is correct |
86 |
Correct |
540 ms |
54380 KB |
Output is correct |
87 |
Correct |
420 ms |
39788 KB |
Output is correct |
88 |
Correct |
449 ms |
40684 KB |
Output is correct |
89 |
Correct |
468 ms |
49456 KB |
Output is correct |
90 |
Correct |
264 ms |
29420 KB |
Output is correct |
91 |
Correct |
458 ms |
44652 KB |
Output is correct |
92 |
Correct |
473 ms |
46316 KB |
Output is correct |
93 |
Correct |
534 ms |
53484 KB |
Output is correct |
94 |
Correct |
480 ms |
48108 KB |
Output is correct |
95 |
Correct |
460 ms |
41964 KB |
Output is correct |
96 |
Correct |
447 ms |
41708 KB |
Output is correct |
97 |
Correct |
547 ms |
54252 KB |
Output is correct |
98 |
Correct |
447 ms |
41452 KB |
Output is correct |
99 |
Correct |
483 ms |
47688 KB |
Output is correct |
100 |
Correct |
543 ms |
52972 KB |
Output is correct |