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
#include <bits/stdc++.h>
#include "message.h"
#include "poszukiwania.h"

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

int main(){

	//LL odp = 0;
	//SignalLength();SeqLength();SignalAt;SeqAt
	// 
	LL M = SeqLength();
	LL S = SignalLength();
	LL poczatekS = (MyNodeId() * S) / NumberOfNodes();
	LL koniecS = ((MyNodeId() + 1) * S) / NumberOfNodes();
	LL poczatekM = (MyNodeId() * M) / NumberOfNodes();
	LL koniecM = ((MyNodeId() + 1) * M) / NumberOfNodes();
//	LL koniec = M - S + ((MyNodeId()+1) * (M-S)) / NumberOfNodes();
//  for (long long i = poczatek; i < koniec; ++i) {

    LL SS = koniecS - poczatekS;
    LL MM = koniecM - poczatekM;
//	cin >> siglength;
	vector <LL> sig(SS);
	vector <int> odp(int(MM-SS));
	for (int i; i < SS; ++i)
		sig[i] = SignalAt(poczatekS + i);
	//cin >> seqlength;
	vector <LL>	seq(MM);
	for (int i = 0; i < koniecM; ++i)
		seq[i] = SeqAt(poczatekM + i);
	for (int i = 0, j = 0; i < MM - SS; ++i, j = 0){
		//int j = 0;
		for (; j < SS; j++)
		     if(sig[j] != seq[i+j]) break;
		
		if(j == SS) odp[i] = 1;
	}
	
	if (MyNodeId() > 0) {
		for(auto i: odp)
         PutInt(0, i);
         Send(0);
  } else {  // MyNodeId == 0
    for (int instancja = 1; instancja < NumberOfNodes(); ++instancja){
        Receive(instancja);
       for(auto &i: odp)
        i += GetInt(instancja);
      }
      LL suma = 0;
      int N = NumberOfNodes();
      for(auto i: odp)
         if ( i == N ) suma++;
     cout << suma << endl;
     }
}