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