I keep getting TLE on test case 6 of the following question : https://codeforces.me/contest/559/problem/B here is a link to my code, https://codeforces.me/contest/559/submission/108124634 thank you!
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
I keep getting TLE on test case 6 of the following question : https://codeforces.me/contest/559/problem/B here is a link to my code, https://codeforces.me/contest/559/submission/108124634 thank you!
Название |
---|
Most probably your recursion is running into an infinite loop.
Yeah, I checked for that but I am dividing the length by 2 at every call so I don't see that happening.
actually your time complexity is O(n^2).
Because you are calling recursion 4 times. So, you are forming a tree with height log2(n) with 4 calls everytime.
hence, net complexity = 4^(log2(n))=n^2.
(Feel free to Correct me if I am Wrong).
Yeah, that seems to be the case. Maybe use memorization to try and speed it up, if you cannot reduce number of recursion nodes.
https://codeforces.me/contest/559/submission/29503685 this code is almost same as mine and it got accepted. It has the same recursive calls.
There is a tiny (but very significant) difference in the two codes: in the accepted version they use the functions directly in the return, but in yours you calculate the values before. The reason this matters is because in the accepted version, if the first part of the and statement returned
false
, the code won't evaluate the rest of the and statement, because it knows that the expression will be false (becausex&0 = 0
for any valuex
). This means that in the accepted version, there is a good chance many of the recursive calls are actually skipped. Here is an accepted version of your code, where I explicitly skipped the second recursive call if the first one failed. 108130742 Note that you shouldn't rely on this in the future because it's an unproven heuristic, and I'm pretty sure it's possible to make a hack test that causes the code to run in $$$O(n^2)$$$.I tried submitting using the same fix and still this fails. Did I miss something? 108130830
Changing the substring comparison back to the comparing them letter-by-letter made it pass pretty comfortably: 108131602. There are two reasons that this could've happened:
Oh okay okay, got your point!
Thanks! =)
oh I got it. but I am still getting tle at 91 https://codeforces.me/contest/559/submission/108131756
It passes if you submit it in 64 bit: 108132405. In my experience, in most cases 64 bit is better (it's often faster and it has things like 128 bit ints), so if I were you, I would submit everything in 64 bit.
thanks a lot man! Is there any downside to submitting in 64 bit?
There are none that I know of, but I can't definitively say that 64 bit is always better. Maybe someone who understands the nuances of both better can comment here.
I once faced an issue with the 64 bit compiler while making a comparator:
Ah yes, I forgot about that. That is an example of the issue mentioned in this blog, where 64 bit c++ has weird precision issues when working with doubles. I think it's still worth it to submit in 64 bit, especially since it's possible to fix this issue by adding one line to your template (see the blog).
I somehow managed to improve your code and now it passes 90 test cases. Final Link: 108130830
Here's my submission to this problem: 108130352. Though, I don't see any difference between these but yours still fails, if you find any let me know as well.