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

TLE的请注意下.

Posted by 2008550914 at 2010-04-10 10:35:45 on Problem 1200
搞了半天,原来是单输入单输出,让我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:
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