#include <iostream>
using namespace std;
char a[2505][2505];
int f[2505][2505], g[2505][2505], d[2505];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
d[j] = n;
cin >> a[i][j];
if (a[i][j] == '1') f[i][j] = f[i - 1][j] + 1;
else f[i][j] = 0;
}
}
for (int i = n; i >= 1; i--) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == '1') g[i][j] = g[i + 1][j] + 1;
else g[i][j] = 0;
if (a[i][j] == '1') {
d[1] = min(d[1], f[i][j] + g[i][j] - 1);
}
}
}
int ma = m;
for (int i = 1; i <= n; i++) {
int h = n, k = n, c = 0;
for (int j = 1; j <= m; j++) {
if (a[i][j] == '1') {
c++;
h = min(h, f[i][j]);
k = min(k, g[i][j]);
d[c] = min(d[c], h + k - 1);
}
else {
if (c != 0) ma = min(ma, c);
c = 0;
h = k = n;
}
}
if (c != 0) ma = min(ma, c);
h = k = n;
c = 0;
for (int j = m; j >= 1; j--) {
if (a[i][j] == '1') {
c++;
h = min(h, f[i][j]);
k = min(k, g[i][j]);
d[c] = min(d[c], h + k - 1);
}
else {
if (c != 0) ma = min(ma, c);
c = 0;
h = k = n;
}
}
if (c != 0) ma = min(ma, c);
}
int res = 1e9;
for (int i = 1; i <= ma; i++) {
res = min(res, i * d[i]);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
10 ms |
27740 KB |
Output is correct |
4 |
Correct |
10 ms |
27608 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
2516 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
10 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
12 |
Correct |
0 ms |
2652 KB |
Output is correct |
13 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
3164 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
23 |
Incorrect |
2 ms |
4956 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
6748 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
4956 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
11228 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
6236 KB |
Output isn't correct |
29 |
Incorrect |
4 ms |
9256 KB |
Output isn't correct |
30 |
Incorrect |
4 ms |
8284 KB |
Output isn't correct |
31 |
Incorrect |
4 ms |
7004 KB |
Output isn't correct |
32 |
Incorrect |
4 ms |
13148 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
10588 KB |
Output isn't correct |
34 |
Incorrect |
3 ms |
6492 KB |
Output isn't correct |
35 |
Incorrect |
5 ms |
8616 KB |
Output isn't correct |
36 |
Incorrect |
8 ms |
8732 KB |
Output isn't correct |
37 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
38 |
Incorrect |
127 ms |
61716 KB |
Output isn't correct |
39 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
40 |
Incorrect |
13 ms |
18780 KB |
Output isn't correct |
41 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
42 |
Incorrect |
1 ms |
6884 KB |
Output isn't correct |
43 |
Incorrect |
102 ms |
61640 KB |
Output isn't correct |
44 |
Incorrect |
5 ms |
17244 KB |
Output isn't correct |
45 |
Incorrect |
145 ms |
61676 KB |
Output isn't correct |
46 |
Incorrect |
94 ms |
61752 KB |
Output isn't correct |
47 |
Incorrect |
131 ms |
61524 KB |
Output isn't correct |
48 |
Incorrect |
138 ms |
61704 KB |
Output isn't correct |
49 |
Incorrect |
89 ms |
61524 KB |
Output isn't correct |
50 |
Incorrect |
88 ms |
61788 KB |
Output isn't correct |
51 |
Incorrect |
94 ms |
61528 KB |
Output isn't correct |
52 |
Incorrect |
121 ms |
61524 KB |
Output isn't correct |
53 |
Incorrect |
131 ms |
61652 KB |
Output isn't correct |
54 |
Incorrect |
83 ms |
61808 KB |
Output isn't correct |
55 |
Incorrect |
87 ms |
61656 KB |
Output isn't correct |
56 |
Incorrect |
90 ms |
61524 KB |
Output isn't correct |
57 |
Incorrect |
84 ms |
61776 KB |
Output isn't correct |
58 |
Incorrect |
84 ms |
61680 KB |
Output isn't correct |
59 |
Incorrect |
83 ms |
61784 KB |
Output isn't correct |
60 |
Incorrect |
82 ms |
61524 KB |
Output isn't correct |
61 |
Incorrect |
85 ms |
61524 KB |
Output isn't correct |
62 |
Incorrect |
82 ms |
61524 KB |
Output isn't correct |
63 |
Incorrect |
79 ms |
61524 KB |
Output isn't correct |
64 |
Incorrect |
84 ms |
61752 KB |
Output isn't correct |
65 |
Incorrect |
79 ms |
61780 KB |
Output isn't correct |
66 |
Incorrect |
92 ms |
61652 KB |
Output isn't correct |
67 |
Incorrect |
88 ms |
61784 KB |
Output isn't correct |
68 |
Incorrect |
80 ms |
61780 KB |
Output isn't correct |
69 |
Incorrect |
87 ms |
61716 KB |
Output isn't correct |
70 |
Incorrect |
55 ms |
52268 KB |
Output isn't correct |
71 |
Incorrect |
83 ms |
61756 KB |
Output isn't correct |
72 |
Incorrect |
81 ms |
61620 KB |
Output isn't correct |
73 |
Incorrect |
77 ms |
61572 KB |
Output isn't correct |
74 |
Incorrect |
86 ms |
61628 KB |
Output isn't correct |
75 |
Incorrect |
85 ms |
61764 KB |
Output isn't correct |
76 |
Incorrect |
75 ms |
61772 KB |
Output isn't correct |
77 |
Incorrect |
124 ms |
61744 KB |
Output isn't correct |
78 |
Incorrect |
81 ms |
61640 KB |
Output isn't correct |
79 |
Incorrect |
76 ms |
61528 KB |
Output isn't correct |
80 |
Incorrect |
82 ms |
61520 KB |
Output isn't correct |
81 |
Incorrect |
71 ms |
61524 KB |
Output isn't correct |
82 |
Incorrect |
96 ms |
61648 KB |
Output isn't correct |
83 |
Incorrect |
100 ms |
61524 KB |
Output isn't correct |
84 |
Incorrect |
73 ms |
61664 KB |
Output isn't correct |
85 |
Incorrect |
108 ms |
61524 KB |
Output isn't correct |
86 |
Incorrect |
129 ms |
61644 KB |
Output isn't correct |
87 |
Incorrect |
76 ms |
61524 KB |
Output isn't correct |
88 |
Incorrect |
92 ms |
61768 KB |
Output isn't correct |
89 |
Incorrect |
81 ms |
61520 KB |
Output isn't correct |
90 |
Incorrect |
72 ms |
52288 KB |
Output isn't correct |
91 |
Incorrect |
97 ms |
61772 KB |
Output isn't correct |
92 |
Incorrect |
79 ms |
61640 KB |
Output isn't correct |
93 |
Incorrect |
83 ms |
61780 KB |
Output isn't correct |
94 |
Incorrect |
107 ms |
61524 KB |
Output isn't correct |
95 |
Incorrect |
108 ms |
61524 KB |
Output isn't correct |
96 |
Incorrect |
88 ms |
61760 KB |
Output isn't correct |
97 |
Incorrect |
92 ms |
61776 KB |
Output isn't correct |
98 |
Incorrect |
108 ms |
61580 KB |
Output isn't correct |
99 |
Incorrect |
76 ms |
61656 KB |
Output isn't correct |
100 |
Incorrect |
77 ms |
61524 KB |
Output isn't correct |