Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why Runtime error

Posted by hjbf at 2007-08-05 16:56:10 on Problem 3320
#include<stdio.h>
long a[1000002],b[1000002],c[2][1000002];
int f(int sum)
{
	int i;
	for(i=0;i<sum;i++)
	{
		if(c[1][i]==0)  return 0;
	}
	return 1;
}
int main()
{
 long i,j,k,n,sum,sign,max;
 scanf("%ld",&n);
 max=0;
 for(i=1;i<=n;i++)
 {
	scanf("%ld",&a[i]);
	b[a[i]]+=1;
	if(a[i]>max)
		max=a[i];
 }
 sum=0;
 for(i=0,j=0;i<=max;i++)
 {
	if(b[i])
	{
		sum+=1;
		c[0][j++]=i;
	}
 }
 sign=n;
 for(i=1;i<=sum;i++)
 {
	for(j=0;j<sum;j++)
	{
		if(c[0][j]==a[i])
		{
			c[1][j]+=1;
			break;
		}
	}
 }
 if(sum==n||f(sum))
 {
	printf("%ld\n",sum);
 }
 else
 {
	for(k=1;i<=n;i++)
	{
		for(j=0;j<sum;j++)
			if(c[0][j]==a[i])
			{
				c[1][j]+=1;
				break;
			}
		if(f(sum))
		{
			while(1)
			{
				for(j=0;j<sum;j++)
					if(c[0][j]==a[k])
					{
						c[1][j]-=1;
						k+=1;
						break;
					}
				if(f(sum)==0)
				{
					k-=1;
					for(j=0;j<sum;j++)
					{
						if(c[0][j]==a[k])
						{
							c[1][j]+=1;
							break;
						}
					}
					break;
				}
			}
			if(sign>i-k+1)  sign=i-k+1;
		}
	}
	printf("%ld\n",sign);
 }
return 1;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator