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
#include<iostream>
#include<cstdio>
#include "message.h"
#include "poszukiwania.h"
using namespace std;

#define MX 500000
int w[MX];
int wzor[MX];
int P[MX];

int main(){
	
	int N,M;
	
	N=SeqLength();
	M=SignalLength();
	
	for(int i=0;i<N;++i){
		w[i]=SeqAt(i+1);
	}
	
	for(int i=0;i<M;++i){
		wzor[i]=SignalAt(i+1);
	}
	
	--N;
	--M;
	
	int j=0;
	int i=0;
    int wyn=0;
	while(i < N)
    {
		if(wzor[j] == w[i])
		{
			j++;
			i++;
		}
		if (j == M)
		{
			++wyn;
			j = P[j-1];
		}
		else if(wzor[j] != w[i])
		{
			if(j != 0) j = P[j-1];
			else i = i+1;
		}
    }
	if( MyNodeId() == 0 ) printf("%d",wyn);
}