#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,n,N) for(int i = n; i<=N; ++i)
#define rap(i,n,N) for(int i = n; i>=N; --i)
#define For(i,n,N) for(int i = n; i< N; ++i)
#define endl '\n'
#define pb push_back
#define all(x) x.begin(),x.end()
#define mems(x,y) memset(x,y,sizeof x)
#define ari(x) array<int,x>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first
#define se second
const int MAX = 2500 + 5;
mt19937 rng(time(NULL));
int n,m,mnr,mnc,cnt,y[MAX][MAX],z[MAX][MAX],ans;
char c;
bool x[MAX][MAX];
vector<ari(3)> v;
inline bool cek(int r,int c,int dr,int dc){
return y[r][c] - y[r-dr][c] - y[r][c-dc] + y[r-dr][c-dc] == dr*dc;
}
inline bool solve(int dr,int dc){
rep(i,1,n)mems(z[i], 0);
rep(i,dr,n)rep(j,dc,m)if(x[i][j] && cek(i,j,dr,dc)){
z[i][j]++;
z[i-dr][j]--;
z[i][j-dc]--;
z[i-dr][j-dc]++;
}
rap(i,n,1)rap(j,m,1){
z[i][j]+= z[i+1][j]+z[i][j+1]-z[i+1][j+1];
if((!!z[i][j])!=x[i][j])return 0;
}
return 1;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
mnr = n, mnc = m;
rep(i,1,n){
rep(j,1,m){
cin>>c;
x[i][j] = c=='1';
y[i][j] = y[i-1][j]+y[i][j-1]-y[i-1][j-1]+x[i][j];
}
}
int k = min(mnr, mnc);
int le,ri,mid;
le = 1, ri = k;
while(le<=ri){
mid = le+ri>>1;
if(solve(mid, mid))k = mid, le = mid+1;
else ri = mid-1;
}
int r,c;
r = c = k;
if(r+1<=mnr && solve(r+1, c)){
++r;
le = r+1, ri = mnr;
while(le<=ri){
mid = le+ri>>1;
if(solve(mid, c))r = mid, le = mid+1;
else ri = mid-1;
}
}
else if(c+1<=mnc){
le = c+1, ri = mnc;
while(le<=ri){
mid = le+ri>>1;
if(solve(r, mid))c = mid, le = mid+1;
else ri = mid-1;
}
}
cout<<r*c<<endl;
return 0;
}
Compilation message
bomb.cpp: In function 'int main()':
bomb.cpp:62:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
62 | mid = le+ri>>1;
| ~~^~~
bomb.cpp:72:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
72 | mid = le+ri>>1;
| ~~^~~
bomb.cpp:80:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | mid = le+ri>>1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
41 ms |
40916 KB |
Output is correct |
4 |
Correct |
43 ms |
41012 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
0 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
0 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
1364 KB |
Output is correct |
18 |
Correct |
1 ms |
1616 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1236 KB |
Output is correct |
22 |
Correct |
1 ms |
1492 KB |
Output is correct |
23 |
Correct |
1 ms |
2004 KB |
Output is correct |
24 |
Correct |
1 ms |
1620 KB |
Output is correct |
25 |
Correct |
1 ms |
2004 KB |
Output is correct |
26 |
Correct |
1 ms |
2004 KB |
Output is correct |
27 |
Correct |
6 ms |
5460 KB |
Output is correct |
28 |
Correct |
7 ms |
5460 KB |
Output is correct |
29 |
Incorrect |
10 ms |
7124 KB |
Output isn't correct |
30 |
Correct |
13 ms |
8020 KB |
Output is correct |
31 |
Correct |
9 ms |
6356 KB |
Output is correct |
32 |
Correct |
10 ms |
7508 KB |
Output is correct |
33 |
Correct |
13 ms |
8404 KB |
Output is correct |
34 |
Correct |
7 ms |
6356 KB |
Output is correct |
35 |
Correct |
14 ms |
8404 KB |
Output is correct |
36 |
Correct |
14 ms |
8404 KB |
Output is correct |
37 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
38 |
Correct |
186 ms |
55480 KB |
Output is correct |
39 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
40 |
Incorrect |
45 ms |
17492 KB |
Output isn't correct |
41 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
42 |
Incorrect |
2 ms |
2004 KB |
Output isn't correct |
43 |
Correct |
346 ms |
55476 KB |
Output is correct |
44 |
Incorrect |
12 ms |
8404 KB |
Output isn't correct |
45 |
Incorrect |
306 ms |
55476 KB |
Output isn't correct |
46 |
Correct |
276 ms |
55512 KB |
Output is correct |
47 |
Incorrect |
372 ms |
55476 KB |
Output isn't correct |
48 |
Correct |
342 ms |
55476 KB |
Output is correct |
49 |
Correct |
369 ms |
55560 KB |
Output is correct |
50 |
Correct |
363 ms |
55480 KB |
Output is correct |
51 |
Correct |
356 ms |
55476 KB |
Output is correct |
52 |
Correct |
389 ms |
55476 KB |
Output is correct |
53 |
Correct |
415 ms |
55500 KB |
Output is correct |
54 |
Correct |
325 ms |
55376 KB |
Output is correct |
55 |
Correct |
340 ms |
55372 KB |
Output is correct |
56 |
Correct |
309 ms |
55500 KB |
Output is correct |
57 |
Correct |
336 ms |
55472 KB |
Output is correct |
58 |
Correct |
310 ms |
55544 KB |
Output is correct |
59 |
Correct |
352 ms |
55476 KB |
Output is correct |
60 |
Correct |
393 ms |
55436 KB |
Output is correct |
61 |
Correct |
360 ms |
55476 KB |
Output is correct |
62 |
Correct |
437 ms |
55356 KB |
Output is correct |
63 |
Correct |
307 ms |
55420 KB |
Output is correct |
64 |
Correct |
282 ms |
55476 KB |
Output is correct |
65 |
Correct |
367 ms |
55480 KB |
Output is correct |
66 |
Correct |
308 ms |
55372 KB |
Output is correct |
67 |
Correct |
435 ms |
55480 KB |
Output is correct |
68 |
Correct |
381 ms |
55372 KB |
Output is correct |
69 |
Correct |
363 ms |
55372 KB |
Output is correct |
70 |
Correct |
253 ms |
44460 KB |
Output is correct |
71 |
Correct |
346 ms |
55468 KB |
Output is correct |
72 |
Correct |
351 ms |
55372 KB |
Output is correct |
73 |
Correct |
372 ms |
55476 KB |
Output is correct |
74 |
Correct |
422 ms |
55476 KB |
Output is correct |
75 |
Correct |
368 ms |
55372 KB |
Output is correct |
76 |
Correct |
391 ms |
55476 KB |
Output is correct |
77 |
Correct |
403 ms |
55476 KB |
Output is correct |
78 |
Correct |
434 ms |
55472 KB |
Output is correct |
79 |
Correct |
340 ms |
55472 KB |
Output is correct |
80 |
Correct |
355 ms |
55476 KB |
Output is correct |
81 |
Correct |
409 ms |
55468 KB |
Output is correct |
82 |
Correct |
376 ms |
55476 KB |
Output is correct |
83 |
Correct |
389 ms |
55480 KB |
Output is correct |
84 |
Correct |
374 ms |
55468 KB |
Output is correct |
85 |
Correct |
380 ms |
55500 KB |
Output is correct |
86 |
Correct |
485 ms |
55476 KB |
Output is correct |
87 |
Incorrect |
426 ms |
55468 KB |
Output isn't correct |
88 |
Correct |
369 ms |
55476 KB |
Output is correct |
89 |
Correct |
448 ms |
55468 KB |
Output is correct |
90 |
Correct |
266 ms |
44584 KB |
Output is correct |
91 |
Correct |
432 ms |
55468 KB |
Output is correct |
92 |
Correct |
479 ms |
55468 KB |
Output is correct |
93 |
Correct |
478 ms |
55468 KB |
Output is correct |
94 |
Correct |
470 ms |
55472 KB |
Output is correct |
95 |
Correct |
375 ms |
55472 KB |
Output is correct |
96 |
Correct |
369 ms |
55412 KB |
Output is correct |
97 |
Correct |
532 ms |
55472 KB |
Output is correct |
98 |
Correct |
429 ms |
55476 KB |
Output is correct |
99 |
Correct |
527 ms |
55476 KB |
Output is correct |
100 |
Correct |
493 ms |
55468 KB |
Output is correct |