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
#include "poszukiwania.h"
#include "message.h"
#include <cstdio>
typedef long long ll;
const ll E=5463458053,F=3367900313;
ll mlen(){return SeqLength();}
ll mat(ll i){return SeqAt(i+1);}
ll slen(){return SignalLength();}
ll sat(ll i){return SignalAt(i+1);}
ll shash(ll s){ll i,h=0;for(i=0;i<s;++i)h+=sat(i);return h+E*sat(0)+F*sat(s-1);}
ll mhash(ll k,ll s){ll i,h=0;for(i=0;i<s;++i)h+=mat(k+i);return h+E*mat(k)+F*mat(k+s-1);}
ll chk(ll k,ll s){ll i;for(i=0;i<s;++i)if(sat(i)!=mat(k+i))return 0;return 1;}
ll sol(){
    ll n=NumberOfNodes(),k=MyNodeId(),m=SeqLength(),s=SignalLength(),hs=shash(s),hm,r=0,i;
    if(k+s>=m)return 0;
    hm=mhash(k,s);
    while(k+s<m){
        if(hs==hm)r+=1;//chk(k,s);
        if(k+s+n>=m)break;
        hm-=E*mat(k)+F*mat(k+s-1);
        for(i=0;i<n;++i)hm+=mat(k+s+i)-mat(k+i);
        k+=n;
        hm+=E*mat(k)+F*mat(k+s-1);
    }
    return r;
}
int main(){
    ll i,r=sol();
    if(!MyNodeId()){for(i=1;i<NumberOfNodes();++i)r+=GetInt(Receive(-1));printf("%lld\n",r);}else{PutInt(0,r);Send(0);}
    return 0;
}