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

int main(){
    long long i,t,tmp;
    int instancja;
    //vector<int> SigAt,SeqAt;
    //int SignalLength, SeqLength;
    //cin>>SignalLength>>SeqLength;
    //SigAt.resize(SignalLength);
    //SeqAt.resize(SeqLength);

    //for(i=0;i<SignalLength;i++) cin>>SigAt[i];
    //for(i=0;i<SeqLength;i++) cin>>SeqAt[i];
    long long cnt=0;
    long long poczatek=(SeqLength()/NumberOfNodes())*(MyNodeId()+1);
    long long koniec=2*SignalLength()+1+SeqLength();
    long long p[koniec];
    p[0]=0; p[SignalLength()+1]=0;
    for(i=1,t=0;i<koniec;i++){
        if(i<=SignalLength()){
            while(t>0&&SignalAt(t+1)!=SignalAt(i+1)) t=p[t-1];
            if(SignalAt(t+1)==SignalAt(i+1)) p[i]=++t;
            else p[i]=0;
        }
        else if(i==SignalLength()+1)p[i]=0;
        else{
            while(t>0&&SignalAt(t+1)!=SeqAt(i-SignalLength())) t=p[t-1];
            if(SignalAt(t+1)==SeqAt(i-SignalLength())) p[i]=++t;
            else p[i]=0;
            if(p[i]==SignalLength())cnt++;
        }
    }
    if(MyNodeId()!=0){
        PutLL(0,cnt);
        Send(0);
    }
    else{
        for(i=0;i<NumberOfNodes();i++){
            instancja=Receive(-1);
            cnt+=GetLL(instancja);
        }
        cout<<cnt/NumberOfNodes();
    }

    return 0;
}