№ | Пользователь | Рейтинг |
---|---|---|
1 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 160 |
4 | atcoder_official | 159 |
4 | Um_nik | 159 |
6 | djm03178 | 156 |
7 | adamant | 153 |
8 | luogu_official | 149 |
8 | awoo | 149 |
10 | TheScrasse | 146 |
Название |
---|
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.me/blog/entry/17507