I had been participating in contests for a long time, but something strange kept happening to me.
In some specific questions (particularly those involving hash maps or dictionaries), I always take contests in Python.
When I submitted solutions for questions involving hash maps, some of them would get accepted, but for others, I would get a TLE (Time Limit Exceeded).
Sometimes these questions would pass the pretests but then fail during system testing or higher test cases with a TLE. This same incident happened to my friend as well. When this first happened to me, I thought maybe my logic was incorrect or that I had solved it wrong. But then, when I checked solutions on streams like those of Shyaan or Aryancc, I found that my logic was correct. So, what was the issue?
One of my friends then suggested that I try solving the problem in C++.** So, I converted the same code to C++** and submitted it, and it worked for the exact same question that had given a TLE in Python.
In my last contest([contest:Hello 2025]), while solving Question B(2057B - Gorilla and the Exam) (another question involving hash maps), I submitted it in Python(299618966), and it passed the pretests. Then, suddenly, I remembered my previous experience with this issue. To be safe, I converted the same code into C++ and submitted it(299648513).
The contest results showed that my C++ submission for Question B was accepted. Out of curiosity, I submitted the same Python code afterward, and it gave a TLE on Test Case 17(299728582). That’s when I felt relieved, knowing I had done the right thing by submitting the C++ version during the contest.
In conclusion, I say this: Never trust Python dictionaries—they can betray you. So, can anyone help me with this? Because I really like submitting code in Python. Also, has this kind of incident ever happened to you as well?
Read this blog: https://mirror.codeforces.com/blog/entry/101817
thanks
I got the same issue with c++. unordered_map which is considered to be faster gave TLE(299715651). The same with map, which is ordered and has a O(log(n)) overall complexity passed the verdict(299715692)
map is faster than unordered_map
in CP Python is trash language
Nah Python is competitively viable. Unless if it's USACO, but that's mostly because their Python judge doesn't use pypy.
Proof Python can work on CodeForces:
I click the link -> A Mountain of TLE -> Python gives much TLE -> Python is trash language
welcome to #pythonsucks this is the beginning of #pythonsucks
At least I actually have more than 5 submissions on my account, also in about 99% of cases TLE is a skill issue and not a language issue
It is not too bad.
https://mirror.codeforces.com/contest/2057/submission/299628938
If it's anything, I still sometimes forget about Python dicts sometimes being like this. If it's anything, C++ also can have a similar issue with unordered_map https://mirror.codeforces.com/blog/entry/62393.