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;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int cost = 0;
vector<vector<int>> sums(n, vector<int>(m, 0));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j) {
int x;
cin >> x;
sums[i][j] = (x == 1 ? 1 : -1);
if(x == 1) {
++cost;
}
/*if(i > 0) sums[i][j] += sums[i-1][j];
if(j > 0) sums[i][j] += sums[i][j-1];
if(i > 0 && j > 0) sums[i][j] -= sums[i-1][j-1];*/
if(i > 0) {
sums[i][j] += sums[i-1][j];
}
}
}
int ma = 0;
for(int i = 0; i < n; ++i) {
for(int j = i; j < n; ++j) {
int cumul = 0;
for(int k = 0; k < m; ++k) {
cumul += sums[j][k];
if(i > 0) {
cumul -= sums[i-1][k];
}
ma = max(ma, cumul);
if(cumul < 0) {
cumul = 0;
}
}
}
}
cout << cost - ma << endl;
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... |