#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][j]++;
dp[i+r][j]--;
dp[i][j+c]--;
dp[i+r][j+c]++;
}
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; 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][j-1]+f[i-1][j]-f[i-1][j-1];
int j = W;
for (int i = 1; i <= H; i++){
int l = 1, r = j;
while (l <= r){
int mid = (l+r)/2;
if (check(i, mid)){
j = mid;
l = mid+1;
}
else r = mid-1;
}
ans = max(ans, i*j);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
10 ms |
54456 KB |
Output is correct |
4 |
Correct |
10 ms |
54620 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4440 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4600 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
2 ms |
6488 KB |
Output is correct |
17 |
Correct |
2 ms |
8792 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
3 ms |
10844 KB |
Output is correct |
20 |
Correct |
4 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 |
5 ms |
10900 KB |
Output is correct |
24 |
Correct |
3 ms |
10844 KB |
Output is correct |
25 |
Correct |
4 ms |
10844 KB |
Output is correct |
26 |
Correct |
5 ms |
11100 KB |
Output is correct |
27 |
Correct |
4 ms |
14940 KB |
Output is correct |
28 |
Correct |
12 ms |
14940 KB |
Output is correct |
29 |
Correct |
246 ms |
14984 KB |
Output is correct |
30 |
Correct |
118 ms |
14936 KB |
Output is correct |
31 |
Correct |
100 ms |
14984 KB |
Output is correct |
32 |
Correct |
91 ms |
14936 KB |
Output is correct |
33 |
Correct |
170 ms |
17068 KB |
Output is correct |
34 |
Correct |
11 ms |
13404 KB |
Output is correct |
35 |
Correct |
33 ms |
16988 KB |
Output is correct |
36 |
Correct |
249 ms |
19088 KB |
Output is correct |
37 |
Correct |
2 ms |
6492 KB |
Output is correct |
38 |
Execution timed out |
1083 ms |
55440 KB |
Time limit exceeded |
39 |
Correct |
1 ms |
6488 KB |
Output is correct |
40 |
Execution timed out |
1030 ms |
27224 KB |
Time limit exceeded |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
11 ms |
10900 KB |
Output is correct |
43 |
Execution timed out |
1070 ms |
55460 KB |
Time limit exceeded |
44 |
Execution timed out |
1016 ms |
19088 KB |
Time limit exceeded |
45 |
Execution timed out |
1052 ms |
55632 KB |
Time limit exceeded |
46 |
Execution timed out |
1012 ms |
55632 KB |
Time limit exceeded |
47 |
Execution timed out |
1060 ms |
55444 KB |
Time limit exceeded |
48 |
Execution timed out |
1062 ms |
55636 KB |
Time limit exceeded |
49 |
Correct |
689 ms |
55660 KB |
Output is correct |
50 |
Execution timed out |
1058 ms |
55608 KB |
Time limit exceeded |
51 |
Execution timed out |
1056 ms |
55456 KB |
Time limit exceeded |
52 |
Execution timed out |
1025 ms |
55632 KB |
Time limit exceeded |
53 |
Execution timed out |
1028 ms |
55584 KB |
Time limit exceeded |
54 |
Execution timed out |
1031 ms |
55888 KB |
Time limit exceeded |
55 |
Execution timed out |
1066 ms |
55636 KB |
Time limit exceeded |
56 |
Execution timed out |
1031 ms |
55636 KB |
Time limit exceeded |
57 |
Execution timed out |
1027 ms |
55632 KB |
Time limit exceeded |
58 |
Execution timed out |
1026 ms |
55432 KB |
Time limit exceeded |
59 |
Execution timed out |
1040 ms |
55632 KB |
Time limit exceeded |
60 |
Execution timed out |
1020 ms |
55632 KB |
Time limit exceeded |
61 |
Execution timed out |
1042 ms |
55640 KB |
Time limit exceeded |
62 |
Execution timed out |
1040 ms |
55444 KB |
Time limit exceeded |
63 |
Execution timed out |
1010 ms |
55636 KB |
Time limit exceeded |
64 |
Execution timed out |
1045 ms |
55456 KB |
Time limit exceeded |
65 |
Execution timed out |
1065 ms |
55448 KB |
Time limit exceeded |
66 |
Execution timed out |
1038 ms |
55640 KB |
Time limit exceeded |
67 |
Execution timed out |
1047 ms |
55636 KB |
Time limit exceeded |
68 |
Execution timed out |
1028 ms |
55632 KB |
Time limit exceeded |
69 |
Execution timed out |
1078 ms |
55636 KB |
Time limit exceeded |
70 |
Execution timed out |
1057 ms |
49744 KB |
Time limit exceeded |
71 |
Execution timed out |
1039 ms |
55632 KB |
Time limit exceeded |
72 |
Execution timed out |
1025 ms |
55632 KB |
Time limit exceeded |
73 |
Execution timed out |
1045 ms |
55636 KB |
Time limit exceeded |
74 |
Execution timed out |
1058 ms |
55636 KB |
Time limit exceeded |
75 |
Execution timed out |
1102 ms |
55644 KB |
Time limit exceeded |
76 |
Execution timed out |
1039 ms |
55632 KB |
Time limit exceeded |
77 |
Execution timed out |
1058 ms |
55444 KB |
Time limit exceeded |
78 |
Execution timed out |
1081 ms |
55444 KB |
Time limit exceeded |
79 |
Execution timed out |
1016 ms |
55632 KB |
Time limit exceeded |
80 |
Execution timed out |
1048 ms |
55636 KB |
Time limit exceeded |
81 |
Execution timed out |
1072 ms |
55528 KB |
Time limit exceeded |
82 |
Execution timed out |
1050 ms |
55508 KB |
Time limit exceeded |
83 |
Execution timed out |
1046 ms |
55632 KB |
Time limit exceeded |
84 |
Execution timed out |
1008 ms |
55636 KB |
Time limit exceeded |
85 |
Execution timed out |
1046 ms |
55640 KB |
Time limit exceeded |
86 |
Execution timed out |
1034 ms |
55644 KB |
Time limit exceeded |
87 |
Execution timed out |
1042 ms |
55620 KB |
Time limit exceeded |
88 |
Execution timed out |
1061 ms |
55464 KB |
Time limit exceeded |
89 |
Execution timed out |
1040 ms |
55604 KB |
Time limit exceeded |
90 |
Execution timed out |
1032 ms |
49744 KB |
Time limit exceeded |
91 |
Execution timed out |
1022 ms |
55756 KB |
Time limit exceeded |
92 |
Execution timed out |
1066 ms |
55636 KB |
Time limit exceeded |
93 |
Execution timed out |
1039 ms |
55608 KB |
Time limit exceeded |
94 |
Execution timed out |
1059 ms |
55612 KB |
Time limit exceeded |
95 |
Execution timed out |
1014 ms |
55448 KB |
Time limit exceeded |
96 |
Execution timed out |
1055 ms |
55452 KB |
Time limit exceeded |
97 |
Execution timed out |
1060 ms |
55456 KB |
Time limit exceeded |
98 |
Execution timed out |
1064 ms |
55636 KB |
Time limit exceeded |
99 |
Execution timed out |
1036 ms |
55424 KB |
Time limit exceeded |
100 |
Execution timed out |
1042 ms |
55636 KB |
Time limit exceeded |