#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, total = 0;
cin >> n >> m;
vector<vector<int>> a(n);
for (int i = 0; i < n; i++) {
a[i].resize(m);
for (int j = 0; j < m; j++) {
int x;
cin >> x;
if (x == 0) {
a[i][j] = +1;
} else {
a[i][j] = -1;
total++;
}
}
}
int sol = (int) 1e9;
for (int l = 0; l < n; l++) {
vector<int> sum(m, 0);
for (int r = l; r < n; r++) {
for (int j = 0; j < m; j++) {
sum[j] += a[r][j];
}
int pm = 0, p = 0;
for (int j = 0; j < m; j++) {
p += sum[j];
sol = min(sol, p - pm);
pm = max(pm, p);
}
}
}
sol += total;
cout << sol << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
248 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
504 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
8184 KB |
Output is correct |
2 |
Correct |
81 ms |
8184 KB |
Output is correct |
3 |
Correct |
77 ms |
8184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1528 KB |
Output is correct |
2 |
Correct |
19 ms |
1528 KB |
Output is correct |
3 |
Correct |
19 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
380 KB |
Output is correct |
2 |
Correct |
10 ms |
376 KB |
Output is correct |
3 |
Correct |
10 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
3388 KB |
Output is correct |
2 |
Correct |
177 ms |
3448 KB |
Output is correct |
3 |
Correct |
175 ms |
3268 KB |
Output is correct |