-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path1200CrazySearch.cpp
More file actions
59 lines (57 loc) · 978 Bytes
/
1200CrazySearch.cpp
File metadata and controls
59 lines (57 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<stdio.h>
#define MOD 84673
using namespace std;
char s[16000000];
int n,nc;
int bucket[MOD];
struct T
{
char w[20];
int next;
}pool[1600000];
int ELFhash(char *key, int M)
{
unsigned int h=0;
while(*key)
{
h=(h<<4)+ *key++;
unsigned int g= h&0xF0000000;
if(g) h^=g>>24;
h&=~g;
}
return h%M;
}
int ne;
int found(char *w)
{
char ww[20];
for(int i=0;i<n;i++)
ww[i]=w[i];
ww[n]='\0';
int h=ELFhash(ww,MOD);
int i;
for(i=bucket[h];i!=-1;i=pool[i].next)
{
if(!strcmp(ww,pool[i].w)) return 1;
}
pool[ne].next=bucket[h];
strcpy(pool[ne].w,ww);
bucket[h]=ne;
ne++;
return 0;
}
int main()
{
int cnt=0;
scanf("%d%d",&n,&nc);
scanf("%s",s);
int len=strlen(s);
memset(bucket,-1,sizeof(bucket));
for(int i=0;i+n-1<len;i++)
{
if(!found(s+i)) cnt++;
}
printf("%d\n",cnt);
return 0;
}