№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3880 |
2 | jiangly | 3669 |
3 | ecnerwala | 3654 |
4 | Benq | 3627 |
5 | orzdevinwang | 3612 |
6 | Geothermal | 3569 |
6 | cnnfls_csy | 3569 |
8 | jqdai0815 | 3532 |
9 | Radewoosh | 3522 |
10 | gyh20 | 3447 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | awoo | 161 |
2 | maomao90 | 160 |
3 | adamant | 156 |
4 | maroonrk | 153 |
5 | atcoder_official | 149 |
6 | -is-this-fft- | 148 |
6 | SecondThread | 148 |
8 | Petr | 147 |
9 | nor | 144 |
10 | cry | 143 |
Название |
---|
Auto comment: topic has been translated by Kane (original revision, translated revision, compare)
I first tried solving it with double hashing with primes 31 and 37. I got WA on Test 9. I changed the modulo, again WA on Test 9, so I realized it was because some hash was becoming zero along the way, and that's certainly not good when hashing...
My workaround was to make a list of primes and choose two randomly until all hashes are positive. I got AC with that. Here's the code -> C++ Double Hashing
Построим строку А, такую что А = S + S. Теперь, мы должны найти первое вхождение строки Т в А. Это можно сделать очень легко с KMP.
Спасибо. KMP это очень круто, не спорю. Но хотелось бы сдать именно двойными хешами.
http://ideone.com/fAZQpx вот, если очень нужно хешами — код на java, но суть понятна
PS: там и одинарный заходит — http://ideone.com/zBAMZh
По твоему коду: Во-первых, убери
s[i] - 'a' + 1
— в задаче могут быть символы начиная с 33 кода. Во-вторых сделай p разными, и больше чем 53 — хотя бы больше чем размер алфавитаI understand that you're asking specifically for the hashing solution, so you probably already know, but this problem can be solved simply by adding a copy of S to itself and then running KMP.
Here's the code for this solution: KMP Code (the hashing solution is above)
Везде пишу двойные хэши от Burunduk1 и всегда работает) Ссылка на его пост про хэши: http://codeforces.com/blog/entry/17507