I am trying to solve http://mirror.codeforces.com/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://mirror.codeforces.com/contest/514/submission/9883601
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
I am trying to solve http://mirror.codeforces.com/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://mirror.codeforces.com/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://mirror.codeforces.com/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://mirror.codeforces.com/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