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_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
int num1 = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
num1 += a[i][j];
}
}
int res = num1;
vector<int> s(m);
for (int x1 = 0; x1 < n; ++x1) {
fill(s.begin(), s.end(), 0);
for (int x2 = x1; x2 < n; ++x2) {
int cur = 0, sum = 0;
for (int i = 0; i < m; ++i) {
sum += (a[x2][i]? -1 : +1);
s[i] += sum;
res = min(res, num1 + s[i] - cur);
cur = max(cur, s[i]);
}
}
}
cout << res << '\n';
return 0;
}
# | 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... |