Created
June 10, 2021 13:16
-
-
Save maskmanlucifer/6bba002040351b0bcd2a6162eadbc0ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> String hashing. | |
>>> Resources: | |
Tutorial no. 1: https://cp-algorithms.com/string/string-hashing.html | |
Tutorial n0. 2:https://www.quora.com/q/threadsiiithyderabad/String-Hashing-for-competitive-programming | |
>>> Implementation: | |
const ll mod=1000000009; | |
const ll P1=53; | |
ll powk1[1000000]; | |
ll hash1=0; | |
void power() | |
{ | |
ll flag=1; | |
for(ll i=0;i<1000000;i++) | |
{ | |
powk1[i]=flag; | |
flag=flag*P1; | |
flag=flag%mod; | |
} | |
} | |
/*hash calculation.*/ | |
void hashing(string s) | |
{ | |
ll hash1=0; | |
ll j=0; | |
for(auto c:s) | |
{ | |
hash1=(hash1+((c-'a'+1)*powk1[j]))%mod; | |
j++; | |
} | |
} | |
>>> Problems: | |
Problem-1 : https://www.codechef.com/problems/CHEFSHIP/ | |
Solution : https://www.codechef.com/viewsolution/33331757 | |
Problem-2 : https://www.codechef.com/problems/CONVSTR/ | |
Solution : https://www.codechef.com/viewsolution/33539615 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment