Submission #8009

# Submission time Handle Problem Language Result Execution time Memory
8009 2014-08-27T05:46:14 Z jhs7jhs Orchard (NOI14_orchard) C++
25 / 25
264 ms 122964 KB
#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 time Memory Grader output
1 Correct 0 ms 122964 KB Output is correct
2 Correct 0 ms 122964 KB Output is correct
3 Correct 0 ms 122964 KB Output is correct
4 Correct 0 ms 122964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 122964 KB Output is correct
2 Correct 0 ms 122964 KB Output is correct
3 Correct 0 ms 122964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 122964 KB Output is correct
2 Correct 100 ms 122964 KB Output is correct
3 Correct 116 ms 122964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 122964 KB Output is correct
2 Correct 24 ms 122964 KB Output is correct
3 Correct 20 ms 122964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 122964 KB Output is correct
2 Correct 4 ms 122964 KB Output is correct
3 Correct 8 ms 122964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 264 ms 122964 KB Output is correct
2 Correct 264 ms 122964 KB Output is correct
3 Correct 256 ms 122964 KB Output is correct