#include <bits/stdc++.h>
using namespace std;
const int NM = 2500, inf = 1e9+7;
int N, M, Up[NM+5][NM+5], Down[NM+5][NM+5], Left[NM+5][NM+5], Right[NM+5][NM+5], H = +inf, W = +inf;
int mx[NM+5], ans = 0;
char a[NM+5][NM+5];
void preprocess(){
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
if (a[i][j] == '1'){
Up[i][j] = Up[i-1][j]+1;
Left[i][j] = Left[i][j-1]+1;
}
for (int i = N; i >= 1; i--)
for (int j = M; j >= 1; j--)
if (a[i][j] == '1'){
Down[i][j] = Down[i+1][j]+1;
Right[i][j] = Right[i][j+1]+1;
H = min(H, Up[i][j]+Down[i][j]-1);
W = min(W, Left[i][j]+Right[i][j]-1);
}
for (int i = 1; i <= H; i++) mx[i] = +inf;
}
int main(){
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];
preprocess();
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++){
if (Down[i][j] == 1){
int l = -inf, r = +inf;
for (int k = 1; k <= H; k++){
if (i-k+1 < 1) continue;
l = max(l, j-Left[i-k+1][j]+1);
r = min(r, j+Right[i-k+1][j]-1);
mx[k] = min(mx[k], r-l+1);
}
}
if (Up[i][j] == 1){
int l = -inf, r = +inf;
for (int k = 1; k <= H; k++){
if (i+k-1 > N) continue;
l = max(l, j-Left[i+k-1][j]+1);
r = min(r, j+Right[i+k-1][j]-1);
mx[k] = min(mx[k], r-l+1);
}
}
}
for (int i = 1; i <= H; i++) ans = max(ans, i*mx[i]);
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
21 ms |
73308 KB |
Output is correct |
4 |
Correct |
19 ms |
73348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
5468 KB |
Output is correct |
18 |
Correct |
1 ms |
3164 KB |
Output is correct |
19 |
Correct |
2 ms |
7516 KB |
Output is correct |
20 |
Correct |
2 ms |
7516 KB |
Output is correct |
21 |
Correct |
1 ms |
860 KB |
Output is correct |
22 |
Correct |
2 ms |
5208 KB |
Output is correct |
23 |
Correct |
2 ms |
7516 KB |
Output is correct |
24 |
Correct |
2 ms |
7512 KB |
Output is correct |
25 |
Correct |
3 ms |
7772 KB |
Output is correct |
26 |
Incorrect |
3 ms |
8024 KB |
Output isn't correct |
27 |
Incorrect |
6 ms |
14168 KB |
Output isn't correct |
28 |
Correct |
3 ms |
7260 KB |
Output is correct |
29 |
Correct |
6 ms |
15708 KB |
Output is correct |
30 |
Correct |
7 ms |
15840 KB |
Output is correct |
31 |
Correct |
4 ms |
9564 KB |
Output is correct |
32 |
Correct |
5 ms |
13916 KB |
Output is correct |
33 |
Correct |
7 ms |
15544 KB |
Output is correct |
34 |
Correct |
3 ms |
7512 KB |
Output is correct |
35 |
Correct |
4 ms |
7516 KB |
Output is correct |
36 |
Incorrect |
8 ms |
19036 KB |
Output isn't correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
264 ms |
104692 KB |
Output is correct |
39 |
Correct |
1 ms |
600 KB |
Output is correct |
40 |
Correct |
31 ms |
39260 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
8028 KB |
Output is correct |
43 |
Correct |
141 ms |
100384 KB |
Output is correct |
44 |
Correct |
8 ms |
17756 KB |
Output is correct |
45 |
Correct |
176 ms |
102620 KB |
Output is correct |
46 |
Correct |
154 ms |
104528 KB |
Output is correct |
47 |
Correct |
179 ms |
102768 KB |
Output is correct |
48 |
Correct |
118 ms |
104532 KB |
Output is correct |
49 |
Incorrect |
107 ms |
104568 KB |
Output isn't correct |
50 |
Correct |
109 ms |
104584 KB |
Output is correct |
51 |
Correct |
120 ms |
104456 KB |
Output is correct |
52 |
Correct |
115 ms |
104572 KB |
Output is correct |
53 |
Correct |
118 ms |
104272 KB |
Output is correct |
54 |
Correct |
100 ms |
89460 KB |
Output is correct |
55 |
Correct |
104 ms |
87156 KB |
Output is correct |
56 |
Correct |
211 ms |
104576 KB |
Output is correct |
57 |
Correct |
94 ms |
78156 KB |
Output is correct |
58 |
Correct |
97 ms |
89892 KB |
Output is correct |
59 |
Correct |
94 ms |
84240 KB |
Output is correct |
60 |
Correct |
100 ms |
95828 KB |
Output is correct |
61 |
Incorrect |
118 ms |
104564 KB |
Output isn't correct |
62 |
Incorrect |
158 ms |
104532 KB |
Output isn't correct |
63 |
Incorrect |
175 ms |
104528 KB |
Output isn't correct |
64 |
Correct |
100 ms |
89936 KB |
Output is correct |
65 |
Correct |
121 ms |
103820 KB |
Output is correct |
66 |
Correct |
104 ms |
101968 KB |
Output is correct |
67 |
Correct |
108 ms |
104568 KB |
Output is correct |
68 |
Correct |
109 ms |
104536 KB |
Output is correct |
69 |
Correct |
92 ms |
75332 KB |
Output is correct |
70 |
Correct |
60 ms |
34980 KB |
Output is correct |
71 |
Correct |
117 ms |
67668 KB |
Output is correct |
72 |
Correct |
142 ms |
75096 KB |
Output is correct |
73 |
Correct |
138 ms |
74276 KB |
Output is correct |
74 |
Correct |
132 ms |
81492 KB |
Output is correct |
75 |
Correct |
139 ms |
85876 KB |
Output is correct |
76 |
Correct |
141 ms |
90356 KB |
Output is correct |
77 |
Correct |
138 ms |
89208 KB |
Output is correct |
78 |
Correct |
144 ms |
90192 KB |
Output is correct |
79 |
Correct |
72 ms |
25168 KB |
Output is correct |
80 |
Correct |
74 ms |
30288 KB |
Output is correct |
81 |
Correct |
78 ms |
31312 KB |
Output is correct |
82 |
Correct |
143 ms |
92532 KB |
Output is correct |
83 |
Correct |
146 ms |
93776 KB |
Output is correct |
84 |
Correct |
69 ms |
11604 KB |
Output is correct |
85 |
Correct |
126 ms |
91476 KB |
Output is correct |
86 |
Correct |
106 ms |
103928 KB |
Output is correct |
87 |
Correct |
115 ms |
91728 KB |
Output is correct |
88 |
Correct |
145 ms |
91564 KB |
Output is correct |
89 |
Correct |
106 ms |
99408 KB |
Output is correct |
90 |
Correct |
100 ms |
74668 KB |
Output is correct |
91 |
Correct |
121 ms |
95312 KB |
Output is correct |
92 |
Correct |
125 ms |
96888 KB |
Output is correct |
93 |
Correct |
108 ms |
103288 KB |
Output is correct |
94 |
Correct |
107 ms |
97664 KB |
Output is correct |
95 |
Correct |
144 ms |
93776 KB |
Output is correct |
96 |
Correct |
146 ms |
93320 KB |
Output is correct |
97 |
Correct |
115 ms |
104056 KB |
Output is correct |
98 |
Correct |
139 ms |
92240 KB |
Output is correct |
99 |
Correct |
105 ms |
96632 KB |
Output is correct |
100 |
Correct |
105 ms |
103036 KB |
Output is correct |