#include "message.h" #include "poszukiwania.h" #include<iostream> #define MAX 1500000000 using namespace std; long long tab[5001111]; long long ile[5001111]; void kmp(long long int d){ long long int t=0LL; for(long long int i=2LL;i<=d;i++) { while((t>0LL) && (tab[t] != tab[i-1LL])) t = ile[t]; if(tab[t] == tab[i-1LL]) t++; ile[i] = t; } } int main(){ long long int n,m; n = SignalLength(); m = SeqLength() ; if(n + m <5001100 ){ for(long long int i=0LL;i<n;i++){ tab[i] = SignalAt(i+1LL); } tab[n] = MAX; for(long long int i=n+1LL;i<=n+m;i++){ tab[i] = SeqAt(i - n); } long long int d = n+m+1LL; kmp(d); int sum=0; for(long long int i=0LL;i<=d;i++){ if(ile[i] >= n) sum++; } if(MyNodeId() == 1) cout << sum; } else cout << "42"; return 0; }
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 | #include "message.h" #include "poszukiwania.h" #include<iostream> #define MAX 1500000000 using namespace std; long long tab[5001111]; long long ile[5001111]; void kmp(long long int d){ long long int t=0LL; for(long long int i=2LL;i<=d;i++) { while((t>0LL) && (tab[t] != tab[i-1LL])) t = ile[t]; if(tab[t] == tab[i-1LL]) t++; ile[i] = t; } } int main(){ long long int n,m; n = SignalLength(); m = SeqLength() ; if(n + m <5001100 ){ for(long long int i=0LL;i<n;i++){ tab[i] = SignalAt(i+1LL); } tab[n] = MAX; for(long long int i=n+1LL;i<=n+m;i++){ tab[i] = SeqAt(i - n); } long long int d = n+m+1LL; kmp(d); int sum=0; for(long long int i=0LL;i<=d;i++){ if(ile[i] >= n) sum++; } if(MyNodeId() == 1) cout << sum; } else cout << "42"; return 0; } |