#include<bits/stdc++.h>
using namespace std;
const int MAX = 2500 + 5;
int n,m,x[MAX][MAX],pf[MAX][MAX],atk[MAX][MAX];
char c;
int get(int x1,int y1,int x2,int y2){
x1--, y1--;
return pf[x2][y2] - pf[x2][y1] - pf[x1][y2] + pf[x1][y1];
}
bool bisa(int h,int w){
memset(atk, 0, sizeof atk);
for(int i = h; i<=n; i++){
for(int j = w; j<=m; j++){
if(get(i-h+1, j-w+1, i, j) == h*w){
atk[i-h+1][j-w+1]++;
atk[i-h+1][j+1]--;
atk[i+1][j-w+1]--;
atk[i+1][j+1]++;
}
}
}
for(int i = 1; i<=n; i++){
for(int j = 1; j<=m; j++){
atk[i][j] = atk[i-1][j] + atk[i][j-1] - atk[i-1][j-1] + atk[i][j];
if(atk[i][j]){
if(!x[i][j])return false;
}
else {
if(x[i][j])return false;
}
}
}
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin>>n>>m;
for(int i = 1; i<=n; i++){
for(int j = 1; j<=m; j++){
cin>>c;
x[i][j] = (c=='1');
pf[i][j] = pf[i-1][j] + pf[i][j-1] - pf[i-1][j-1] + x[i][j];
}
}
// bisa(3, 1);
//
// for(int i = 1; i<=n; i++){
// for(int j = 1; j<=m; j++){
// cout<<atk[i][j]<<" ";
// }
// cout<<endl;
// }
int ans = 0;
int w,h;
int le,ri,mid,s;
le = 2, ri = min(n,m);
s = 1;
while(le<=ri){
mid = (le+ri)>>1;
if(bisa(mid, mid))s = mid, le = mid+1;
else ri = mid-1;
}
h = w = s;
if(w+1<=m && bisa(h,w+1)){
le = w+1, ri = m;
while(le<=ri){
mid = (le+ri)>>1;
if(bisa(h, mid))w = mid, le = mid+1;
else ri = mid-1;
}
}
else if(h+1<=n){
le = h+1, ri = n;
while(le<=ri){
mid = (le+ri)>>1;
if(bisa(mid, w))h = mid, le = mid+1;
else ri = mid-1;
}
}
cout<<h*w<<endl;
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:61:6: warning: unused variable 'ans' [-Wunused-variable]
61 | int ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
24788 KB |
Output is correct |
2 |
Correct |
16 ms |
25044 KB |
Output is correct |
3 |
Correct |
40 ms |
44948 KB |
Output is correct |
4 |
Correct |
37 ms |
44976 KB |
Output is correct |
5 |
Correct |
31 ms |
24908 KB |
Output is correct |
6 |
Correct |
31 ms |
24788 KB |
Output is correct |
7 |
Correct |
18 ms |
24916 KB |
Output is correct |
8 |
Correct |
25 ms |
25044 KB |
Output is correct |
9 |
Correct |
25 ms |
25044 KB |
Output is correct |
10 |
Correct |
23 ms |
24976 KB |
Output is correct |
11 |
Correct |
25 ms |
25052 KB |
Output is correct |
12 |
Correct |
24 ms |
24916 KB |
Output is correct |
13 |
Correct |
22 ms |
24916 KB |
Output is correct |
14 |
Correct |
23 ms |
24996 KB |
Output is correct |
15 |
Correct |
26 ms |
24952 KB |
Output is correct |
16 |
Correct |
27 ms |
25044 KB |
Output is correct |
17 |
Correct |
33 ms |
25452 KB |
Output is correct |
18 |
Correct |
33 ms |
25472 KB |
Output is correct |
19 |
Correct |
33 ms |
25684 KB |
Output is correct |
20 |
Correct |
33 ms |
25684 KB |
Output is correct |
21 |
Correct |
33 ms |
25324 KB |
Output is correct |
22 |
Correct |
36 ms |
25536 KB |
Output is correct |
23 |
Correct |
36 ms |
25768 KB |
Output is correct |
24 |
Correct |
36 ms |
25556 KB |
Output is correct |
25 |
Correct |
36 ms |
25684 KB |
Output is correct |
26 |
Correct |
36 ms |
25776 KB |
Output is correct |
27 |
Correct |
46 ms |
27860 KB |
Output is correct |
28 |
Correct |
47 ms |
27988 KB |
Output is correct |
29 |
Incorrect |
51 ms |
28968 KB |
Output isn't correct |
30 |
Correct |
59 ms |
29800 KB |
Output is correct |
31 |
Correct |
51 ms |
28628 KB |
Output is correct |
32 |
Correct |
54 ms |
29356 KB |
Output is correct |
33 |
Correct |
66 ms |
30076 KB |
Output is correct |
34 |
Correct |
52 ms |
28372 KB |
Output is correct |
35 |
Correct |
59 ms |
29960 KB |
Output is correct |
36 |
Correct |
60 ms |
30036 KB |
Output is correct |
37 |
Incorrect |
26 ms |
25052 KB |
Output isn't correct |
38 |
Correct |
342 ms |
74572 KB |
Output is correct |
39 |
Correct |
25 ms |
25052 KB |
Output is correct |
40 |
Incorrect |
111 ms |
37844 KB |
Output isn't correct |
41 |
Incorrect |
27 ms |
25044 KB |
Output isn't correct |
42 |
Incorrect |
35 ms |
25772 KB |
Output isn't correct |
43 |
Correct |
492 ms |
74740 KB |
Output is correct |
44 |
Incorrect |
58 ms |
30036 KB |
Output isn't correct |
45 |
Incorrect |
390 ms |
74724 KB |
Output isn't correct |
46 |
Correct |
325 ms |
74668 KB |
Output is correct |
47 |
Incorrect |
537 ms |
74812 KB |
Output isn't correct |
48 |
Correct |
428 ms |
74772 KB |
Output is correct |
49 |
Correct |
398 ms |
74664 KB |
Output is correct |
50 |
Correct |
456 ms |
74772 KB |
Output is correct |
51 |
Correct |
490 ms |
74844 KB |
Output is correct |
52 |
Correct |
561 ms |
74928 KB |
Output is correct |
53 |
Correct |
513 ms |
74832 KB |
Output is correct |
54 |
Correct |
459 ms |
74728 KB |
Output is correct |
55 |
Correct |
483 ms |
74864 KB |
Output is correct |
56 |
Correct |
467 ms |
74896 KB |
Output is correct |
57 |
Correct |
572 ms |
74764 KB |
Output is correct |
58 |
Correct |
527 ms |
74904 KB |
Output is correct |
59 |
Correct |
597 ms |
75012 KB |
Output is correct |
60 |
Correct |
436 ms |
75024 KB |
Output is correct |
61 |
Correct |
487 ms |
75028 KB |
Output is correct |
62 |
Correct |
552 ms |
74864 KB |
Output is correct |
63 |
Correct |
410 ms |
74972 KB |
Output is correct |
64 |
Correct |
367 ms |
75024 KB |
Output is correct |
65 |
Correct |
492 ms |
74848 KB |
Output is correct |
66 |
Correct |
399 ms |
74732 KB |
Output is correct |
67 |
Correct |
561 ms |
74796 KB |
Output is correct |
68 |
Correct |
607 ms |
75028 KB |
Output is correct |
69 |
Correct |
647 ms |
75080 KB |
Output is correct |
70 |
Correct |
335 ms |
65184 KB |
Output is correct |
71 |
Correct |
448 ms |
74836 KB |
Output is correct |
72 |
Correct |
504 ms |
75144 KB |
Output is correct |
73 |
Correct |
503 ms |
75084 KB |
Output is correct |
74 |
Correct |
624 ms |
75124 KB |
Output is correct |
75 |
Correct |
514 ms |
75120 KB |
Output is correct |
76 |
Correct |
524 ms |
75108 KB |
Output is correct |
77 |
Correct |
542 ms |
75120 KB |
Output is correct |
78 |
Correct |
622 ms |
75164 KB |
Output is correct |
79 |
Correct |
378 ms |
75164 KB |
Output is correct |
80 |
Correct |
369 ms |
75144 KB |
Output is correct |
81 |
Correct |
473 ms |
75108 KB |
Output is correct |
82 |
Correct |
494 ms |
75160 KB |
Output is correct |
83 |
Correct |
570 ms |
75164 KB |
Output is correct |
84 |
Correct |
365 ms |
75156 KB |
Output is correct |
85 |
Correct |
578 ms |
75088 KB |
Output is correct |
86 |
Correct |
462 ms |
75160 KB |
Output is correct |
87 |
Incorrect |
505 ms |
75156 KB |
Output isn't correct |
88 |
Correct |
586 ms |
75164 KB |
Output is correct |
89 |
Correct |
512 ms |
75160 KB |
Output is correct |
90 |
Correct |
370 ms |
65232 KB |
Output is correct |
91 |
Correct |
555 ms |
75160 KB |
Output is correct |
92 |
Correct |
498 ms |
75160 KB |
Output is correct |
93 |
Correct |
463 ms |
75116 KB |
Output is correct |
94 |
Correct |
564 ms |
75164 KB |
Output is correct |
95 |
Correct |
557 ms |
75232 KB |
Output is correct |
96 |
Correct |
574 ms |
75136 KB |
Output is correct |
97 |
Correct |
556 ms |
75192 KB |
Output is correct |
98 |
Correct |
619 ms |
75160 KB |
Output is correct |
99 |
Correct |
483 ms |
75160 KB |
Output is correct |
100 |
Correct |
444 ms |
75052 KB |
Output is correct |