In this problem http://www.spoj.com/problems/PLD/ , what is the best way to use rabin_karp?
To precalculate hashes,or add-delete numbers? Cause I am stuck at this 4 hours now... :(
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
In this problem http://www.spoj.com/problems/PLD/ , what is the best way to use rabin_karp?
To precalculate hashes,or add-delete numbers? Cause I am stuck at this 4 hours now... :(
Название |
---|
Substring [l..r] is a palindrome when it equals to its reversed version. So you can precalc hashes for s and for reversed s. Then you may check for all k-substrings if they are equal to its reversed versions.
The time to hash a substring,is the same with pass it with a for loop right? So instead precalculate all hashes,why not to check with naive way??
Except if I calculate the hash via adding and deleting new and last character. I know How to do that in normal string,but in reversing string,I need to delete in reversing mode of rabin-karp.
For example if I have "asd" as string,rabin karp says:
(a*BASE + s)*BASE + d, and when I delete I says -=a*BASE^2.
but in reversing string,I need to delete from the other side,so I should say: -d,and after /=BASE. That gives me strange numbers....
I cant get it!!!
The time to hash a substring,is the same with pass it with a for loop right?
There is a way to calculate polynomial hash of substring in O(1) with O(n) precalc. It's like prefix-sums.
Ok,I figured out !!! Thanks for the time!!!