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 |
TLE 不知道原因,按照我的思路,我这样应该是不会超时的#include <stdio.h> unsigned long int a[1000000], b[1000000], c[1000000]; int main() { unsigned long int p, i, m, j, count=0, flag; while(scanf("%d",&p)==1) { count=0; if(p==0) { printf("0\n"); continue; } for(i=0; i<p; i++) { scanf("%d",&a[i]); if(count) { flag=1; for(j=0; j<count; j++) { if(b[j]==a[i]) { flag=0; while(j<count-1) { b[j]=b[j+1]; c[j]=c[j+1]; j++; } b[j]=a[i]; c[j]=i; if(m>(i+1-c[0])) { m=i+1-c[0]; } break; } } if(flag) { b[j]=a[i]; count++; c[j]=i; m=i+1-c[0]; } } else { b[0]=a[i]; count++; c[0]=i; m=1; } } if(count==1) { printf("1\n"); continue; } if(count==p) { printf("%d\n",p); continue; } printf("%d\n", m); } return 0; } 我的一直是TLE,但是,不知道哪里慢下来的,请大家帮忙指点。 Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator