Submission #8009

#TimeUsernameProblemLanguageResultExecution timeMemory
8009jhs7jhsOrchard (NOI14_orchard)C++98
25 / 25
264 ms122964 KiB
#include<stdio.h> int n,m,a[1000000]={0},b[151][100001]={0}; int sum[151][100001]={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...