This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |