#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const ll N = 2600;
ll n,m;
char a[N][N];
ll mins,temp,mins1;
void sub1() {
if(n == 1) {
mins = 1e9;
if(a[1][1] == '1') temp++;
for(int i=2; i<=m; i++) {
if(a[1][i] == a[1][i-1] && a[1][i] == '1') {
temp++;
}
else {
if(temp != 0)mins = min(mins,temp);
if(a[1][i] == '0') temp = 0;
else temp = 1;
}
}
if(temp != 0)mins = min(mins,temp);
cout << mins << endl;
}
else if(m == 1) {
mins = 1e9;
if(a[1][1] == '1') temp++;
for(int i=2; i<=n; i++) {
if(a[i][1] == a[i-1][1] && a[i][1] == '1') {
temp++;
}
else {
if(temp != 0)mins = min(mins,temp);
if(a[i][1] == '0') temp = 0;
else temp = 1;
}
}
if(temp != 0)mins = min(mins,temp);
cout << mins << endl;
}
}
int main() {
cin >> n >> m;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
cin >> a[i][j];
}
}
if(n == 1 || m == 1) {
sub1();
return 0;
}
mins = 1e9;
mins1 = 1e9;
for(int i=1; i<=n; i++) {
temp = 0;
if(a[i][1] == '1') temp++;
for(int j=2; j<=m; j++) {
if(a[i][j] == a[i][j-1] && a[i][j] == '1') {
temp++;
}
else {
// cout << "i " << i << " " << temp << endl;
if(temp != 0)mins = min(mins,temp);
if(a[i][j] == '0') temp = 0;
else temp = 1;
}
}
if(temp != 0)mins = min(mins,temp);
}
if(temp != 0)mins = min(mins,temp);
// cout << "temp " << mins << endl;
temp = 0;
for(int i=1; i<=m; i++) {
temp = 0;
if(a[1][i] == '1') temp++;
for(int j=2; j<=n; j++) {
if(a[j][i] == a[j-1][i] && a[j][i] == '1') {
temp++;
}
else {
// cout << "i " << i << " " << temp << endl;
if(temp != 0)mins1 = min(mins1,temp);
if(a[j][i] == '0') temp = 0;
else temp = 1;
}
}
if(temp != 0)mins = min(mins,temp);
}
if(temp != 0)mins1 = min(mins1,temp);
// cout << mins << " " << mins1 << endl;
cout << mins * mins1 << endl;
}
/*
10 1
0
0
0
1
1
0
0
1
1
1
1 9
011111011
5 6
001000
111110
111110
011110
000100
5 6
111000
111000
111000
111111
011111
5 6
001100
001100
000111
000111
000111
5 1
1
1
0
1
0
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
6612 KB |
Output is correct |
4 |
Correct |
2 ms |
6612 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
464 KB |
Output isn't correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Incorrect |
3 ms |
980 KB |
Output isn't correct |
28 |
Incorrect |
4 ms |
980 KB |
Output isn't correct |
29 |
Incorrect |
5 ms |
1236 KB |
Output isn't correct |
30 |
Incorrect |
7 ms |
1364 KB |
Output isn't correct |
31 |
Incorrect |
6 ms |
1108 KB |
Output isn't correct |
32 |
Incorrect |
6 ms |
1236 KB |
Output isn't correct |
33 |
Incorrect |
7 ms |
1380 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
1220 KB |
Output isn't correct |
35 |
Incorrect |
8 ms |
1364 KB |
Output isn't correct |
36 |
Correct |
8 ms |
1364 KB |
Output is correct |
37 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
38 |
Correct |
205 ms |
6532 KB |
Output is correct |
39 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
40 |
Incorrect |
27 ms |
2468 KB |
Output isn't correct |
41 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
42 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
43 |
Correct |
210 ms |
6544 KB |
Output is correct |
44 |
Incorrect |
7 ms |
1364 KB |
Output isn't correct |
45 |
Incorrect |
209 ms |
6600 KB |
Output isn't correct |
46 |
Correct |
213 ms |
6588 KB |
Output is correct |
47 |
Incorrect |
208 ms |
6688 KB |
Output isn't correct |
48 |
Incorrect |
207 ms |
6536 KB |
Output isn't correct |
49 |
Correct |
224 ms |
6680 KB |
Output is correct |
50 |
Incorrect |
206 ms |
6536 KB |
Output isn't correct |
51 |
Incorrect |
206 ms |
6560 KB |
Output isn't correct |
52 |
Incorrect |
209 ms |
6652 KB |
Output isn't correct |
53 |
Incorrect |
214 ms |
6580 KB |
Output isn't correct |
54 |
Incorrect |
208 ms |
6644 KB |
Output isn't correct |
55 |
Incorrect |
208 ms |
6640 KB |
Output isn't correct |
56 |
Incorrect |
205 ms |
6640 KB |
Output isn't correct |
57 |
Incorrect |
214 ms |
6580 KB |
Output isn't correct |
58 |
Incorrect |
208 ms |
6576 KB |
Output isn't correct |
59 |
Incorrect |
211 ms |
6644 KB |
Output isn't correct |
60 |
Correct |
213 ms |
6540 KB |
Output is correct |
61 |
Incorrect |
220 ms |
6620 KB |
Output isn't correct |
62 |
Correct |
212 ms |
6720 KB |
Output is correct |
63 |
Correct |
204 ms |
6544 KB |
Output is correct |
64 |
Correct |
207 ms |
6536 KB |
Output is correct |
65 |
Incorrect |
213 ms |
6688 KB |
Output isn't correct |
66 |
Incorrect |
209 ms |
6564 KB |
Output isn't correct |
67 |
Incorrect |
217 ms |
6604 KB |
Output isn't correct |
68 |
Incorrect |
207 ms |
6636 KB |
Output isn't correct |
69 |
Incorrect |
243 ms |
6648 KB |
Output isn't correct |
70 |
Incorrect |
134 ms |
5380 KB |
Output isn't correct |
71 |
Incorrect |
208 ms |
6556 KB |
Output isn't correct |
72 |
Incorrect |
216 ms |
6624 KB |
Output isn't correct |
73 |
Incorrect |
212 ms |
6652 KB |
Output isn't correct |
74 |
Incorrect |
212 ms |
6620 KB |
Output isn't correct |
75 |
Incorrect |
229 ms |
6664 KB |
Output isn't correct |
76 |
Incorrect |
211 ms |
6728 KB |
Output isn't correct |
77 |
Incorrect |
213 ms |
6604 KB |
Output isn't correct |
78 |
Incorrect |
213 ms |
6652 KB |
Output isn't correct |
79 |
Incorrect |
211 ms |
6532 KB |
Output isn't correct |
80 |
Incorrect |
210 ms |
6544 KB |
Output isn't correct |
81 |
Incorrect |
215 ms |
6632 KB |
Output isn't correct |
82 |
Incorrect |
210 ms |
6584 KB |
Output isn't correct |
83 |
Incorrect |
209 ms |
6532 KB |
Output isn't correct |
84 |
Incorrect |
219 ms |
6572 KB |
Output isn't correct |
85 |
Incorrect |
214 ms |
6652 KB |
Output isn't correct |
86 |
Incorrect |
205 ms |
6632 KB |
Output isn't correct |
87 |
Incorrect |
208 ms |
6604 KB |
Output isn't correct |
88 |
Incorrect |
210 ms |
6612 KB |
Output isn't correct |
89 |
Incorrect |
206 ms |
6604 KB |
Output isn't correct |
90 |
Incorrect |
133 ms |
5388 KB |
Output isn't correct |
91 |
Incorrect |
214 ms |
6776 KB |
Output isn't correct |
92 |
Incorrect |
207 ms |
6592 KB |
Output isn't correct |
93 |
Incorrect |
204 ms |
6588 KB |
Output isn't correct |
94 |
Incorrect |
206 ms |
6624 KB |
Output isn't correct |
95 |
Incorrect |
208 ms |
6604 KB |
Output isn't correct |
96 |
Incorrect |
209 ms |
6628 KB |
Output isn't correct |
97 |
Incorrect |
206 ms |
6564 KB |
Output isn't correct |
98 |
Incorrect |
218 ms |
6560 KB |
Output isn't correct |
99 |
Incorrect |
216 ms |
6596 KB |
Output isn't correct |
100 |
Incorrect |
209 ms |
6648 KB |
Output isn't correct |