#include <cstdio> #include <vector> #include "poszukiwania.h" #include "message.h" using namespace std; long long n, m, res; int s (int a){ if (a <= n) return (SignalAt(a)); if (a == n+1) return -1; if (a > n+1) return (SeqAt(a-n-1)); } int main() { if (MyNodeId() == 0) { n = SignalLength(); m = SeqLength(); vector <int> tab(n+m+2); tab[1] = 0; int t = tab[1]; for (int i = 2; i < n+m+2; i++) { while (t > 0 and s(t + 1) != s(i)) t = tab[t]; if (s(t + 1) == s(i)) t++; tab[i] = t; if (t >= n and i > n+1) res++; } printf("%lld", res); } 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 | #include <cstdio> #include <vector> #include "poszukiwania.h" #include "message.h" using namespace std; long long n, m, res; int s (int a){ if (a <= n) return (SignalAt(a)); if (a == n+1) return -1; if (a > n+1) return (SeqAt(a-n-1)); } int main() { if (MyNodeId() == 0) { n = SignalLength(); m = SeqLength(); vector <int> tab(n+m+2); tab[1] = 0; int t = tab[1]; for (int i = 2; i < n+m+2; i++) { while (t > 0 and s(t + 1) != s(i)) t = tab[t]; if (s(t + 1) == s(i)) t++; tab[i] = t; if (t >= n and i > n+1) res++; } printf("%lld", res); } return 0; } |