#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 |
1 ms |
276 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
12360 KB |
Output is correct |
2 |
Correct |
58 ms |
14004 KB |
Output is correct |
3 |
Correct |
62 ms |
13920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1896 KB |
Output is correct |
2 |
Correct |
11 ms |
2240 KB |
Output is correct |
3 |
Correct |
11 ms |
2256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
9 ms |
340 KB |
Output is correct |
3 |
Correct |
9 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
322 ms |
3268 KB |
Output is correct |
2 |
Correct |
327 ms |
3280 KB |
Output is correct |
3 |
Correct |
323 ms |
3264 KB |
Output is correct |