#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
452 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
10048 KB |
Output is correct |
2 |
Correct |
140 ms |
10064 KB |
Output is correct |
3 |
Correct |
136 ms |
10028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2228 KB |
Output is correct |
2 |
Correct |
30 ms |
2144 KB |
Output is correct |
3 |
Correct |
28 ms |
2220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
532 KB |
Output is correct |
3 |
Correct |
6 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
7632 KB |
Output is correct |
2 |
Correct |
183 ms |
7628 KB |
Output is correct |
3 |
Correct |
176 ms |
7688 KB |
Output is correct |