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;
const int MAX = 1e6 + 11;
int a[MAX];
int s[MAX << 1];
int main(){
int n, m; cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i * m + j];
}
}
int c1 = accumulate(a, a + n * m, 0LL);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(a[i * m + j] == 0) a[i * m + j] = -1;
s[(i + 1) * m + j] = s[i * m + j] + a[i * m + j];
}
}
int ans = 0;
for(int l = 0; l < n; l++){
for(int r = l; r < n; r++){
int cur = 0;
for(int j = 0; j < m; j++){
int v = s[(r + 1) * m + j] - s[l * m + j];
cur = max(0, cur + v); ans = max(ans, cur);
}
}
}
cout << c1 - ans << endl;
}
# | 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... |