#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
11964 KB |
Output is correct |
2 |
Correct |
56 ms |
11980 KB |
Output is correct |
3 |
Correct |
50 ms |
11980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1876 KB |
Output is correct |
2 |
Correct |
11 ms |
1876 KB |
Output is correct |
3 |
Correct |
11 ms |
1904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
9 ms |
400 KB |
Output is correct |
3 |
Correct |
8 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
316 ms |
3276 KB |
Output is correct |
2 |
Correct |
326 ms |
3272 KB |
Output is correct |
3 |
Correct |
313 ms |
3268 KB |
Output is correct |