The Modulo Went Negative
const int m = 1e9 + 9;
vector<long long> h; // h[i] = hash of the first i characters, h[0] = 0
vector<long long> p_pow;
// hash of t[l .. l+len-1], scaled by p^l
long long sub(int l, int len) {
return (h[l + len] - h[l]) % m; // line 8
}
sub is compared against the pattern hash scaled the same way. The code is correct on many inputs and then silently misses matches. What is wrong, and why is it intermittent?
Sign in to answer questions and track your progress
Sign In