Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why Runtime error#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator