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 | 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 |
# | User | Contrib. |
---|---|---|
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 | djm03178 | 152 |
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