#pragma GCC optimize("Ofast")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
const int NM = 2500, inf = 1e9+7;
int N, M, f[NM+5][NM+5], dp[NM+5][NM+5], ans = 0, H = +inf, W = +inf;
char a[NM+5][NM+5];
int getf(int x, int y, int u, int v){
return f[u][v]-f[x-1][v]-f[u][y-1]+f[x-1][y-1];
}
bool check(int r, int c){
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++) dp[i][j] = 0;
for (int i = 1; i+r-1 <= N; i++)
for (int j = 1; j+c-1 <= M; j++)
if (getf(i, j, i+r-1, j+c-1) == r*c){
dp[i+r-1][j+c-1]++;
dp[i+r-1][j-1]--;
dp[i-1][j+c-1]--;
dp[i-1][j-1]++;
}
for (int i = N; i >= 1; i--)
for (int j = M; j >= 1; j--){
dp[i][j] += dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1];
if (dp[i][j] == 0 && a[i][j] == '1') return 0;
}
return 1;
}
void preprocess(){
for (int j = 1; j <= M; j++)
for (int i = 1; i <= N; i++){
if (a[i][j] == '0') continue;
int k = i;
while (k <= N && a[k][j] == '1') k++;
H = min(H, k-i);
i = k-1;
}
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++){
if (a[i][j] == '0') continue;
int k = j;
while (k <= M && a[i][k] == '1') k++;
W = min(W, k-j);
j = k-1;
}
}
int main(){
// freopen("BOMB.inp", "r", stdin);
// freopen("BOMB.ans", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++){
cin >> a[i][j];
if (a[i][j] == '1') f[i][j] = 1;
}
preprocess();
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
f[i][j] += f[i-1][j]+f[i][j-1]-f[i-1][j-1];
if (N <= 450 && M <= 450){
int j = W;
for (int i = 1; i <= H; i++){
while (j > 0 && !check(i, j)) j--;
ans = max(ans, i*j);
}
cout << ans;
return 0;
}
int l = 1, r = W;
while (l <= r){
int mid = (l+r)/2;
if (check(H, mid)){
ans = max(ans, H*mid);
l = mid+1;
}
else{
if (H-1 > 0 && check(H-1, mid)) ans = max(ans, (H-1)*mid);
r = mid-1;
}
}
l = 1, r = H;
while (l <= r){
int mid = (l+r)/2;
if (check(mid, W)){
ans = max(ans, mid*W);
l = mid+1;
}
else r = mid-1;
}
int j = W-1;
for (int i = 1; i < H; i++){
if (i*j <= ans) continue;
while (j > 0 && !check(i, j)){
if ((double)clock()/CLOCKS_PER_SEC > 0.95) break;
j--;
}
if ((double)clock()/CLOCKS_PER_SEC > 0.95) break;
ans = max(ans, i*j);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
11 ms |
54620 KB |
Output is correct |
4 |
Correct |
9 ms |
54648 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
2 ms |
8728 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
10844 KB |
Output is correct |
20 |
Correct |
3 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
3 ms |
10840 KB |
Output is correct |
24 |
Correct |
3 ms |
10844 KB |
Output is correct |
25 |
Correct |
3 ms |
10844 KB |
Output is correct |
26 |
Correct |
2 ms |
10844 KB |
Output is correct |
27 |
Correct |
4 ms |
14940 KB |
Output is correct |
28 |
Correct |
6 ms |
13148 KB |
Output is correct |
29 |
Correct |
42 ms |
15192 KB |
Output is correct |
30 |
Correct |
92 ms |
14980 KB |
Output is correct |
31 |
Correct |
54 ms |
13400 KB |
Output is correct |
32 |
Correct |
54 ms |
14980 KB |
Output is correct |
33 |
Correct |
124 ms |
17068 KB |
Output is correct |
34 |
Correct |
9 ms |
13404 KB |
Output is correct |
35 |
Correct |
180 ms |
16008 KB |
Output is correct |
36 |
Correct |
31 ms |
19036 KB |
Output is correct |
37 |
Correct |
2 ms |
4444 KB |
Output is correct |
38 |
Correct |
474 ms |
55656 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
238 ms |
27296 KB |
Output is correct |
41 |
Correct |
1 ms |
4440 KB |
Output is correct |
42 |
Correct |
8 ms |
10840 KB |
Output is correct |
43 |
Correct |
420 ms |
55656 KB |
Output is correct |
44 |
Correct |
155 ms |
19084 KB |
Output is correct |
45 |
Incorrect |
958 ms |
55656 KB |
Output isn't correct |
46 |
Correct |
250 ms |
55660 KB |
Output is correct |
47 |
Incorrect |
958 ms |
55656 KB |
Output isn't correct |
48 |
Correct |
711 ms |
55888 KB |
Output is correct |
49 |
Correct |
189 ms |
55712 KB |
Output is correct |
50 |
Correct |
712 ms |
55472 KB |
Output is correct |
51 |
Correct |
722 ms |
55636 KB |
Output is correct |
52 |
Correct |
689 ms |
55636 KB |
Output is correct |
53 |
Correct |
685 ms |
55656 KB |
Output is correct |
54 |
Correct |
958 ms |
55656 KB |
Output is correct |
55 |
Correct |
933 ms |
55660 KB |
Output is correct |
56 |
Correct |
323 ms |
55656 KB |
Output is correct |
57 |
Correct |
801 ms |
55460 KB |
Output is correct |
58 |
Correct |
839 ms |
55660 KB |
Output is correct |
59 |
Correct |
861 ms |
55888 KB |
Output is correct |
60 |
Correct |
263 ms |
55660 KB |
Output is correct |
61 |
Correct |
247 ms |
55656 KB |
Output is correct |
62 |
Correct |
354 ms |
55960 KB |
Output is correct |
63 |
Correct |
322 ms |
55656 KB |
Output is correct |
64 |
Correct |
325 ms |
55712 KB |
Output is correct |
65 |
Correct |
676 ms |
55656 KB |
Output is correct |
66 |
Correct |
290 ms |
55672 KB |
Output is correct |
67 |
Correct |
821 ms |
55660 KB |
Output is correct |
68 |
Correct |
808 ms |
55708 KB |
Output is correct |
69 |
Correct |
651 ms |
55652 KB |
Output is correct |
70 |
Incorrect |
951 ms |
48704 KB |
Output isn't correct |
71 |
Incorrect |
951 ms |
55888 KB |
Output isn't correct |
72 |
Incorrect |
963 ms |
55660 KB |
Output isn't correct |
73 |
Incorrect |
960 ms |
55448 KB |
Output isn't correct |
74 |
Incorrect |
953 ms |
55892 KB |
Output isn't correct |
75 |
Incorrect |
958 ms |
55652 KB |
Output isn't correct |
76 |
Incorrect |
952 ms |
55888 KB |
Output isn't correct |
77 |
Incorrect |
959 ms |
55892 KB |
Output isn't correct |
78 |
Incorrect |
960 ms |
55656 KB |
Output isn't correct |
79 |
Incorrect |
952 ms |
55632 KB |
Output isn't correct |
80 |
Incorrect |
961 ms |
55632 KB |
Output isn't correct |
81 |
Incorrect |
962 ms |
55656 KB |
Output isn't correct |
82 |
Incorrect |
955 ms |
55656 KB |
Output isn't correct |
83 |
Incorrect |
954 ms |
55652 KB |
Output isn't correct |
84 |
Incorrect |
965 ms |
55656 KB |
Output isn't correct |
85 |
Incorrect |
953 ms |
55768 KB |
Output isn't correct |
86 |
Correct |
951 ms |
55656 KB |
Output is correct |
87 |
Correct |
959 ms |
55892 KB |
Output is correct |
88 |
Incorrect |
960 ms |
55656 KB |
Output isn't correct |
89 |
Incorrect |
953 ms |
55656 KB |
Output isn't correct |
90 |
Incorrect |
955 ms |
49864 KB |
Output isn't correct |
91 |
Incorrect |
964 ms |
55720 KB |
Output isn't correct |
92 |
Incorrect |
971 ms |
55656 KB |
Output isn't correct |
93 |
Incorrect |
965 ms |
55636 KB |
Output isn't correct |
94 |
Incorrect |
960 ms |
55652 KB |
Output isn't correct |
95 |
Incorrect |
955 ms |
55660 KB |
Output isn't correct |
96 |
Incorrect |
960 ms |
55652 KB |
Output isn't correct |
97 |
Incorrect |
962 ms |
55660 KB |
Output isn't correct |
98 |
Incorrect |
957 ms |
55892 KB |
Output isn't correct |
99 |
Incorrect |
956 ms |
55656 KB |
Output isn't correct |
100 |
Correct |
963 ms |
55660 KB |
Output is correct |