I am trying to solve http://codeforces.me/contest/514/problem/C but repeatedly getting wa at test 6.Tried a lot but can't figure out the problem...Link to my solution http://codeforces.me/contest/514/submission/9883601
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3857 |
| 2 | jiangly | 3810 |
| 3 | maroonrk | 3534 |
| 4 | tourist | 3528 |
| 5 | Kevin114514 | 3510 |
| 6 | turmax | 3411 |
| 7 | Um_nik | 3387 |
| 8 | Radewoosh | 3367 |
| 9 | heuristica | 3322 |
| 10 | strapple | 3317 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | maspy | 150 |
| 3 | Um_nik | 145 |
| 4 | Errichto | 139 |
| 5 | adamant | 136 |
| 6 | maroonrk | 134 |
| 7 | nik_exists | 133 |
| 7 | DNR | 133 |
| 9 | AmShZ | 130 |
| 10 | Dominater069 | 129 |
I am trying to solve http://codeforces.me/contest/514/problem/C but repeatedly getting wa at test 6.Tried a lot but can't figure out the problem...Link to my solution http://codeforces.me/contest/514/submission/9883601
| Name |
|---|



=(((str[j]-'a'+1)*(ll)pow(5,j))%mod);pow function is declared likedouble pow(double x, double n)some powers of 5 will not fit into double and number will be truncated(size of double is 8 bytes).
Use your own Pow function to power number modulo mod.
I did but still WA http://codeforces.me/contest/514/submission/9883905
No. You did not. It's still call standart function pow. Rename function to "Pow" with capital letter, or "Bar" or "Foo".
Still no use :( http://codeforces.me/contest/514/submission/9918779
uncomment lines.
//val%=mod; //val+=mod;I had TLE with your code a few days ago. Next step is to replace set::find with binary_search or hashtable.You have to name your pow function other than pow, becasue pow is a C++ function. And your pow function work slow. You should try Log(n) pow or pre-compute pow function
Your bug is in hash calculation: pow function is calculating result in double type. It won't work as you expect: pow can return something like 3e100, it won't be taken by modulo and will moreover loose a lot of significant digits.
I think the solution with trie is better than the hashing one. I haven't perfectly analized your code but maybe the bug is that your hashing is not perfect so I suggest you to implement the trie solution, which is much easier
Why you don't try with different bases?For example try with 37 or 71...
I tried doing it using trie but i cannot figure out the search procedure. Can you help me?
Here is my solution. 12563068