#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2505;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N][N], n, m, k;
bool usedup[N][N], usedr[N][N];
int up[N][N], down[N][N];
int ans[N];
vector<int> v[N];
vector<int> s[N];
void solve(int test_case){
int i, j;
cin >> n >> m;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
char c;
cin >> c;
a[i][j] = (c-'0');
}
}
int mx=mod, my=mod;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(a[i][j] == 1){
if(usedup[i][j])continue;
int t = j;
int tmp = 0;
while(t <= m && a[i][t] == 1){
tmp++;
usedup[i][t] = true;
t++;
}mx = min(mx, tmp);
}
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(a[i][j] == 1){
if(usedr[i][j])continue;
int t = i;
int tmp = 0;
while(t <= n && a[t][j] == 1){
tmp++;
usedr[t][j] = true;
t++;
}my = min(my, tmp);
}
}
}
if(mx == mod){
mx = 0;
my = 0;
}
/// (mx, my) is greedy answer
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(a[i][j])up[i][j] = up[i-1][j]+a[i][j];
}
}
for(i=n;i>=1;i--){
for(j=1;j<=m;j++){
if(a[i][j])down[i][j] = down[i+1][j]+a[i][j];
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(!a[i][j])continue;
int cnt = 1;
int tmp = j;
while(j+1 <= m && a[i][j+1])cnt++,j++;
v[i].pb(tmp);
s[i].pb(cnt);
}
}
for(i=1;i<=m;i++)ans[i] = my;
for(i=1;i<=n;i++){
for(k=0;k<v[i].size();k++){
int j = v[i][k];
int sz = s[i][k];
int a=mod, b=mod, c=0;
for(;sz;sz--, j++){
a = min(a, up[i][j]);
b = min(b, down[i][j]);
c++;
ans[c] = min(ans[c], a+b-1);
}
}
for(k=(int)v[i].size()-1;k>=0;k--){
int sz = s[i][k];
int j = v[i][k]+sz-1;
int a=mod, b=mod, c=0;
for(;sz;sz--, j--){
a = min(a, up[i][j]);
b = min(b, down[i][j]);
c++;
ans[c] = min(ans[c], a+b-1);
}
}
}
// cout << mx << ' ' << my << '\n';
for(i=2;i<=mx;i++)ans[i] = min(ans[i], ans[i-1]);
int res = 0;
// for(i=1;i<=mx;i++)cout << ans[i] << ' '; cout << '\n';
for(i=1;i<=mx;i++)res = max(res, i*ans[i]);
cout << res << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 0
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
/*
6 6
000111
011111
011111
111000
111000
111000
*/
Compilation message
bomb.cpp: In function 'void solve(int)':
bomb.cpp:88:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(k=0;k<v[i].size();k++){
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
25 ms |
42988 KB |
Output is correct |
4 |
Correct |
24 ms |
42988 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
620 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
748 KB |
Output is correct |
10 |
Correct |
1 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
748 KB |
Output is correct |
12 |
Correct |
1 ms |
748 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
748 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
17 |
Correct |
1 ms |
1644 KB |
Output is correct |
18 |
Correct |
1 ms |
1260 KB |
Output is correct |
19 |
Correct |
2 ms |
1644 KB |
Output is correct |
20 |
Correct |
2 ms |
1644 KB |
Output is correct |
21 |
Correct |
1 ms |
876 KB |
Output is correct |
22 |
Correct |
1 ms |
1260 KB |
Output is correct |
23 |
Correct |
1 ms |
1772 KB |
Output is correct |
24 |
Correct |
1 ms |
1644 KB |
Output is correct |
25 |
Correct |
2 ms |
2156 KB |
Output is correct |
26 |
Correct |
2 ms |
2284 KB |
Output is correct |
27 |
Correct |
6 ms |
6508 KB |
Output is correct |
28 |
Correct |
4 ms |
2668 KB |
Output is correct |
29 |
Correct |
8 ms |
8428 KB |
Output is correct |
30 |
Correct |
9 ms |
7276 KB |
Output is correct |
31 |
Correct |
7 ms |
5356 KB |
Output is correct |
32 |
Correct |
8 ms |
7020 KB |
Output is correct |
33 |
Correct |
10 ms |
8940 KB |
Output is correct |
34 |
Correct |
4 ms |
3052 KB |
Output is correct |
35 |
Correct |
6 ms |
3948 KB |
Output is correct |
36 |
Correct |
12 ms |
10476 KB |
Output is correct |
37 |
Correct |
1 ms |
876 KB |
Output is correct |
38 |
Correct |
318 ms |
86444 KB |
Output is correct |
39 |
Correct |
1 ms |
896 KB |
Output is correct |
40 |
Correct |
39 ms |
24428 KB |
Output is correct |
41 |
Correct |
1 ms |
876 KB |
Output is correct |
42 |
Correct |
2 ms |
2284 KB |
Output is correct |
43 |
Correct |
268 ms |
82540 KB |
Output is correct |
44 |
Correct |
11 ms |
9964 KB |
Output is correct |
45 |
Correct |
259 ms |
83948 KB |
Output is correct |
46 |
Correct |
205 ms |
87660 KB |
Output is correct |
47 |
Correct |
260 ms |
83948 KB |
Output is correct |
48 |
Correct |
245 ms |
86380 KB |
Output is correct |
49 |
Correct |
318 ms |
86508 KB |
Output is correct |
50 |
Correct |
251 ms |
86380 KB |
Output is correct |
51 |
Correct |
251 ms |
86380 KB |
Output is correct |
52 |
Correct |
266 ms |
86380 KB |
Output is correct |
53 |
Correct |
252 ms |
85740 KB |
Output is correct |
54 |
Correct |
203 ms |
73196 KB |
Output is correct |
55 |
Correct |
202 ms |
70636 KB |
Output is correct |
56 |
Correct |
326 ms |
87660 KB |
Output is correct |
57 |
Correct |
194 ms |
63852 KB |
Output is correct |
58 |
Correct |
204 ms |
71404 KB |
Output is correct |
59 |
Correct |
204 ms |
67052 KB |
Output is correct |
60 |
Correct |
237 ms |
78312 KB |
Output is correct |
61 |
Correct |
313 ms |
86508 KB |
Output is correct |
62 |
Correct |
296 ms |
86380 KB |
Output is correct |
63 |
Correct |
311 ms |
86508 KB |
Output is correct |
64 |
Correct |
198 ms |
69356 KB |
Output is correct |
65 |
Correct |
256 ms |
85484 KB |
Output is correct |
66 |
Correct |
242 ms |
82284 KB |
Output is correct |
67 |
Correct |
261 ms |
86508 KB |
Output is correct |
68 |
Correct |
267 ms |
86508 KB |
Output is correct |
69 |
Correct |
197 ms |
63084 KB |
Output is correct |
70 |
Correct |
105 ms |
34284 KB |
Output is correct |
71 |
Correct |
164 ms |
55148 KB |
Output is correct |
72 |
Correct |
178 ms |
61292 KB |
Output is correct |
73 |
Correct |
187 ms |
61548 KB |
Output is correct |
74 |
Correct |
179 ms |
64192 KB |
Output is correct |
75 |
Correct |
185 ms |
66308 KB |
Output is correct |
76 |
Correct |
186 ms |
68204 KB |
Output is correct |
77 |
Correct |
193 ms |
68588 KB |
Output is correct |
78 |
Correct |
185 ms |
68972 KB |
Output is correct |
79 |
Correct |
143 ms |
33516 KB |
Output is correct |
80 |
Correct |
143 ms |
35564 KB |
Output is correct |
81 |
Correct |
155 ms |
35436 KB |
Output is correct |
82 |
Correct |
198 ms |
72300 KB |
Output is correct |
83 |
Correct |
195 ms |
72684 KB |
Output is correct |
84 |
Correct |
137 ms |
25964 KB |
Output is correct |
85 |
Correct |
191 ms |
71788 KB |
Output is correct |
86 |
Correct |
303 ms |
85384 KB |
Output is correct |
87 |
Correct |
194 ms |
70764 KB |
Output is correct |
88 |
Correct |
194 ms |
70636 KB |
Output is correct |
89 |
Correct |
237 ms |
80364 KB |
Output is correct |
90 |
Correct |
121 ms |
54252 KB |
Output is correct |
91 |
Correct |
209 ms |
75628 KB |
Output is correct |
92 |
Correct |
234 ms |
77164 KB |
Output is correct |
93 |
Correct |
297 ms |
84460 KB |
Output is correct |
94 |
Correct |
236 ms |
79084 KB |
Output is correct |
95 |
Correct |
199 ms |
72684 KB |
Output is correct |
96 |
Correct |
197 ms |
72068 KB |
Output is correct |
97 |
Correct |
300 ms |
85228 KB |
Output is correct |
98 |
Correct |
200 ms |
71788 KB |
Output is correct |
99 |
Correct |
231 ms |
78700 KB |
Output is correct |
100 |
Correct |
292 ms |
84076 KB |
Output is correct |