#include <stdio.h>
#include <string.h>
int main(){
int i,j,k,l,n,m,ans=1e6,mn,t;
scanf("%d%d",&n,&m);
int a[n+20][m+20];
memset(a,0,sizeof a);
for(i=1;i<=n;++i){
for(j=1;j<=m;++j)scanf("%d",a[i]+j),a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
}
for(i=1;i<=n;++i){
for(j=i;j<=n;++j){
mn=1e6;
for(k=1;k<=m;++k){
t=2*(a[j][k-1]-a[i-1][k-1])-(j-i+1)*k;
if(mn>t)mn=t;
t=a[n][m]+(j-i+1)*(k+1)-2*(a[j][k]-a[i-1][k])+mn;
if(ans>t)ans=t;
}
}
}
printf("%d",ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1208 KB |
Output is correct |
2 |
Correct |
0 ms |
1208 KB |
Output is correct |
3 |
Correct |
0 ms |
1208 KB |
Output is correct |
4 |
Correct |
0 ms |
1208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2316 KB |
Output is correct |
2 |
Correct |
0 ms |
2316 KB |
Output is correct |
3 |
Correct |
0 ms |
2312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
83116 KB |
Output is correct |
2 |
Correct |
98 ms |
83116 KB |
Output is correct |
3 |
Correct |
119 ms |
83120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
9684 KB |
Output is correct |
2 |
Correct |
24 ms |
9684 KB |
Output is correct |
3 |
Correct |
19 ms |
9684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1208 KB |
Output is correct |
2 |
Correct |
8 ms |
1208 KB |
Output is correct |
3 |
Correct |
8 ms |
1208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
4416 KB |
Output is correct |
2 |
Correct |
257 ms |
4420 KB |
Output is correct |
3 |
Correct |
255 ms |
4420 KB |
Output is correct |