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
#include<cstdio>
#include<vector>
using namespace std;
#include "message.h"
#include "poszukiwania.h"
const int MAXN = 1e6+4;
long long m, s;
long long CharAt(long long x)
{
// 	printf("x %lld\n", x);
	if (x <= s) return SignalAt(x);
	if (x == s+1) return -111;
	if (x <= s+m+1) return SeqAt(x - s-1);
	else return -234;
}

int main (){
	
	s = SignalLength();
	m = SeqLength();
	if(MyNodeId() == 0){
		vector<int> w;
		w.clear();
		w.push_back(0);
		w.push_back(0);
	long long k = 0, tomek = 0;
	long long prt;
	for (int i = 2; i < m+s+1; i++)
	{
		prt = CharAt(i);
// 		printf("%d ", prt);
		while(k > 0 && CharAt(k+1) != prt) k = w[k];
		if(CharAt(k+1) == prt) k++;
 		if (i <= s+1) w.push_back(k);
//  		printf("%d: %d %d prt %d\n", i, k, w[i], prt);
		if (k == s) tomek++;

	}
	printf("%lld\n", tomek);}
	return 0;
}