Hello,
I don't understand why my solution got a TLE for problem B. Here is the solution I came up with during the contest: 299645061. I'm quite sure the complexity is O(nlogn) but maybe I'm wrong. Here is another solution that doesn't use del
: 299814673 even though if I remember correctly the complexity of del
is O(1).
Does anyone have similar results?
You got hacked due to hash collisions blowing up your map/dictionary (which Counter is basically). See this blog.
Best way I found of fixing this was to just use str(yourInt) as the keys.
There is also an anti hash test for strings
Yes this worked! Thanks! Do you know why it works?
quit python learn c++ = no more headache
If you wrote unordered_map in this problem in C++ you do also still get a TL :)
Actually python
dict
worked perfectly fine !299628814
if you don't sort the array, your solution will TL
sorting the array is necessary ?
idk how it works, but somehow this happens
with sorting the array [AC]: https://mirror.codeforces.com/contest/2057/submission/299941291
without sorting [TL]: https://mirror.codeforces.com/contest/2057/submission/299941087
nvm , wrong
take a look at this
https://mirror.codeforces.com/contest/2057/submission/299943438
after looking carefully , your code is same as mine but the wrong is with this
what data structure would you use in C++? a std::set?
std::map
i used an unorderd map and got TLE after the contest i rewrote it in map and got acc i really want to know why???
I use c++ but i got TLE because i use unordered_map
Hash collision is the main reason for getting TLE . Your code works O(1) per number which results O(n) for whole array most of the time.But due to hash collision it would be increased to O(n^2) which is inefficient for large inputs.
Hope this helps