#include <cassert>
#include <iostream>
#include <vector>
#define ll int
#define ln "\n"
#define ff first
#define ss second
#define ld long double
const ll INF = 1e9;
const ll MOD = 1e9+7;
using namespace std;
void solve(){
ll n, m; cin >> n >> m;
vector<vector<ll>> a(n+1, vector<ll>(m+1)), left(n+1, vector<ll>(m+2)), right(n+1, vector<ll>(m+2));
for (ll i=1; i<=n; i++)
for (ll j=1; j<=m; j++){
char x; cin >> x;
a[i][j]=x-'0';
}
vector<ll> mxwid(n+1, m);
for (ll i=1; i<=n; i++) {
for (ll j=1; j<=m; j++){
left[i][j] = a[i][j]?left[i][j-1]+1:0;
}
for (ll j=m; j>=1; j--){
right[i][j] = a[i][j]?right[i][j+1]+1:0;
if (a[i][j])mxwid[1]=min(mxwid[1], right[i][j]+left[i][j]-1);
}
}
ll mxh=n;
for (ll j=1; j<=m; j++){
ll l=m, r=m, cc=0;
for (ll i=1; i<=n; i++){
if (a[i][j]){
l=min(l, left[i][j]);
r=min(r, right[i][j]);
cc++;
mxwid[cc]=min(mxwid[cc], l+r-1);
}else{
if (cc)mxh=min(mxh, cc);
cc=0;
l=m; r=m;
}
}
if (cc) mxh=min(mxh, cc);
}
for (ll j=1; j<=m; j++){
ll l=m, r=m, cc=0;
for (ll i=n; i>=1; i--){
if (a[i][j]){
l=min(l, left[i][j]);
r=min(r, right[i][j]);
cc++;
mxwid[cc]=min(mxwid[cc], l+r-1);
}else{
if (cc) mxh=min(mxh, cc);
cc=0;
l=m; r=m;
}
}
if (cc) mxh=min(mxh, cc);
}
ll ans=0;
for (ll i=1; i<=mxh; i++){
// cout << i << ":" << mxwid[i] << ln;
mxwid[i]=min(mxwid[i-1], mxwid[i]);
ans=max(ans, mxwid[i]*i);
}
cout << ans << ln;
}
void setIO(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int main(){
setIO();
ll t=1;
// cin >> t;
while (t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
860 KB |
Output is correct |
4 |
Correct |
1 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
1372 KB |
Output is correct |
28 |
Correct |
2 ms |
1880 KB |
Output is correct |
29 |
Correct |
4 ms |
1884 KB |
Output is correct |
30 |
Correct |
4 ms |
2840 KB |
Output is correct |
31 |
Correct |
3 ms |
2396 KB |
Output is correct |
32 |
Correct |
5 ms |
2396 KB |
Output is correct |
33 |
Correct |
5 ms |
2908 KB |
Output is correct |
34 |
Correct |
2 ms |
1368 KB |
Output is correct |
35 |
Correct |
4 ms |
2908 KB |
Output is correct |
36 |
Correct |
5 ms |
3020 KB |
Output is correct |
37 |
Correct |
0 ms |
344 KB |
Output is correct |
38 |
Correct |
222 ms |
80468 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
21 ms |
10412 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
187 ms |
80024 KB |
Output is correct |
44 |
Correct |
4 ms |
2908 KB |
Output is correct |
45 |
Correct |
189 ms |
80456 KB |
Output is correct |
46 |
Correct |
188 ms |
80208 KB |
Output is correct |
47 |
Correct |
185 ms |
80208 KB |
Output is correct |
48 |
Correct |
170 ms |
80152 KB |
Output is correct |
49 |
Correct |
210 ms |
80152 KB |
Output is correct |
50 |
Correct |
171 ms |
80208 KB |
Output is correct |
51 |
Correct |
171 ms |
80208 KB |
Output is correct |
52 |
Correct |
176 ms |
80212 KB |
Output is correct |
53 |
Correct |
175 ms |
80212 KB |
Output is correct |
54 |
Correct |
149 ms |
80208 KB |
Output is correct |
55 |
Correct |
146 ms |
80020 KB |
Output is correct |
56 |
Correct |
204 ms |
80116 KB |
Output is correct |
57 |
Correct |
189 ms |
80212 KB |
Output is correct |
58 |
Correct |
160 ms |
80208 KB |
Output is correct |
59 |
Correct |
160 ms |
80132 KB |
Output is correct |
60 |
Correct |
172 ms |
80208 KB |
Output is correct |
61 |
Correct |
264 ms |
80276 KB |
Output is correct |
62 |
Correct |
207 ms |
80208 KB |
Output is correct |
63 |
Correct |
213 ms |
80248 KB |
Output is correct |
64 |
Correct |
168 ms |
80044 KB |
Output is correct |
65 |
Correct |
168 ms |
80208 KB |
Output is correct |
66 |
Correct |
164 ms |
80208 KB |
Output is correct |
67 |
Correct |
173 ms |
80212 KB |
Output is correct |
68 |
Correct |
187 ms |
80184 KB |
Output is correct |
69 |
Correct |
145 ms |
80208 KB |
Output is correct |
70 |
Correct |
94 ms |
51552 KB |
Output is correct |
71 |
Correct |
137 ms |
80024 KB |
Output is correct |
72 |
Correct |
146 ms |
80068 KB |
Output is correct |
73 |
Correct |
155 ms |
80208 KB |
Output is correct |
74 |
Correct |
150 ms |
80156 KB |
Output is correct |
75 |
Correct |
146 ms |
80208 KB |
Output is correct |
76 |
Correct |
149 ms |
80156 KB |
Output is correct |
77 |
Correct |
149 ms |
80188 KB |
Output is correct |
78 |
Correct |
177 ms |
80216 KB |
Output is correct |
79 |
Correct |
127 ms |
80208 KB |
Output is correct |
80 |
Correct |
131 ms |
80212 KB |
Output is correct |
81 |
Correct |
132 ms |
80208 KB |
Output is correct |
82 |
Correct |
148 ms |
80212 KB |
Output is correct |
83 |
Correct |
143 ms |
80028 KB |
Output is correct |
84 |
Correct |
135 ms |
80168 KB |
Output is correct |
85 |
Correct |
150 ms |
80208 KB |
Output is correct |
86 |
Correct |
194 ms |
80148 KB |
Output is correct |
87 |
Correct |
158 ms |
80148 KB |
Output is correct |
88 |
Correct |
149 ms |
80212 KB |
Output is correct |
89 |
Correct |
160 ms |
80212 KB |
Output is correct |
90 |
Correct |
97 ms |
51504 KB |
Output is correct |
91 |
Correct |
160 ms |
80152 KB |
Output is correct |
92 |
Correct |
160 ms |
80212 KB |
Output is correct |
93 |
Correct |
198 ms |
80208 KB |
Output is correct |
94 |
Correct |
166 ms |
80464 KB |
Output is correct |
95 |
Correct |
150 ms |
80124 KB |
Output is correct |
96 |
Correct |
148 ms |
80156 KB |
Output is correct |
97 |
Correct |
202 ms |
80072 KB |
Output is correct |
98 |
Correct |
162 ms |
80208 KB |
Output is correct |
99 |
Correct |
161 ms |
80212 KB |
Output is correct |
100 |
Correct |
193 ms |
80208 KB |
Output is correct |