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>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main() {
FAST
int r,c;
int hitone=0;
cin >> r >> c;
int orch[r+1][c+1];
for(int i=1; i<=r; i++) {
for(int j=1; j<=c; j++) {
cin >> orch[i][j];
if(orch[i][j]==1) hitone++;
}
}
int answer = hitone;
int ter, sum;
vector<int>co(c+1);
for(int i=1; i<=r; i++) {
for(int k=1; k<=c; k++) {
co[k]=0;
}
for(int j=i; j<=r; j++) {
sum = 0;
ter = 0;
for(int kol=1; kol<=c; kol++) {
if(orch[j][kol]) {
sum-=1;
} else {
sum+=1;
}
co[kol]+=sum;
answer = min(answer, hitone+co[kol]-ter);
ter = max(ter, co[kol]);
}
}
}
cout << answer << 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... |