제출 #8008

#제출 시각아이디문제언어결과실행 시간메모리
8008jhs7jhs과수원 (NOI14_orchard)C++98
22 / 25
268 ms10892 KiB
#include<stdio.h> int n,m,a[1000000]={0},b[151][5001]={0}; int sum[151][5001]={0}; void f1(void){ int i,sum=0,s=0,t=0,ans=3000000; for(i=0;i<m;i++){ scanf("%d",&a[i]); sum += a[i]; } for(i=0;i<m;i++){ s += 1 - 2*a[i]; if(ans > sum+s-t) ans = sum+s-t; if(t<s) t=s; } printf("%d\n",ans); return; } void f2(void){ int i,j,k,s=0,t=0,ans=2147483647; for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&b[i][j]); sum[i][j] = b[i][j] + sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1]; } } for(i=1;i<=n;i++){ for(j=i;j<=n;j++){ s=t=0; for(k=1;k<=m;k++){ s += (j-i+1) - 2 * (sum[j][k] - sum[i-1][k] - sum[j][k-1] + sum[i-1][k-1]); if(ans > sum[n][m] + s-t) ans = sum[n][m] + s-t; if(t<s) t = s; } } } printf("%d\n",ans); return; } int main() { scanf("%d%d",&n,&m); if(n==1) f1(); else f2(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...