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的请注意下.搞了半天,原来是单输入单输出,让我TLE了n次 #include<iostream> #include<cstdio> #include<cstring> using namespace std; char text[1000000]; int c[128],hash[16000000]; int main(){ int n,nc,i,j,ans,length,sum; scanf("%d %d",&n,&nc); memset(c,0,sizeof(c)); memset(hash,0,sizeof(hash)); scanf("%s",text); length=strlen(text); j=0; for(i=0;i<length;i++){ if(c[text[i]]==0) c[text[i]]=++j; if(j==nc) break; } ans=0; for(i=0;i<=length-n;i++){ sum=0; for(j=i;j<=i+n-1;j++) sum=sum*nc+c[text[j]]-1; if(hash[sum]==0){ hash[sum]=1; ans++; } } printf("%d\n",ans); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator