#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<vector <int> > p;
int n, m, ans = ~0u>>1;
inline int get(int x1,int y1,int x2,int y2){return p[x2][y2] - p[x2][y1-1] - p[x1-1][y2] + p[x1-1][y1-1];}
int main()
{
scanf("%d%d",&n,&m);
p.resize(n+1);p[0].resize(m+1);
int i, j;
for(i=1;i<=n;i++){
p[i].resize(m+1);
for(j=1;j<=m;j++)scanf("%d",&p[i][j]);
}
for(i=1;i<=n;i++)for(j=1;j<=m;j++)p[i][j] += p[i][j-1] + p[i-1][j] - p[i-1][j-1];
for(i=1;i<=n;i++){
for(j=i;j<=n;j++){
int now = 0;
for(int k=1;k<=m;k++){
ans = std::min(ans, (j-i+1) * (k-now) - 2 * get(i, now+1, j, k) + p[n][m]);
if(get(i, now+1, j, k)*2 < (j-i+1) * (k-now))now = k;
}
}
}
printf("%d",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
0 ms |
1240 KB |
Output is correct |
3 |
Correct |
0 ms |
1240 KB |
Output is correct |
4 |
Correct |
0 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1240 KB |
Output is correct |
2 |
Correct |
0 ms |
1240 KB |
Output is correct |
3 |
Correct |
0 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
9056 KB |
Output is correct |
2 |
Correct |
128 ms |
9056 KB |
Output is correct |
3 |
Correct |
128 ms |
9056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
2416 KB |
Output is correct |
2 |
Correct |
24 ms |
2416 KB |
Output is correct |
3 |
Correct |
24 ms |
2416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1240 KB |
Output is correct |
2 |
Correct |
16 ms |
1240 KB |
Output is correct |
3 |
Correct |
16 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
4116 KB |
Output is correct |
2 |
Correct |
588 ms |
4116 KB |
Output is correct |
3 |
Correct |
584 ms |
4116 KB |
Output is correct |