This has happened to me twice, where 1 index hashing is getting TLE but 0 index hashing with same logic is getting Accepted. Not sure if it's python issue or hashing complexity.
TLE — https://codeforces.net/contest/1701/submission/163370464
Accepted — https://codeforces.net/contest/1701/submission/163370574
TLE — https://codeforces.net/contest/1702/submission/163995656
Accepted — https://codeforces.net/contest/1702/submission/163996134
If you look at the test cases, both submissions TLE'd on the same sequence. In fact, this sequence appears in several other contests such as 803C. So I believe that this was an anti-hash test specifically designed to counter a Python hash table that does not change the default 1-based indexing.
So are participants suppose to use array instead of python hash table (dictionary) in such question?
Guess so, an array and custom sorting function is about equivalent to a C++ map. But Python users will always have it rough, most time limits are not designed with Python in mind.
https://codeforces.net/blog/entry/101817
Okay, so turns out that this was due to Anti hash table test and 0 index hashing is not faster than 1 index hashing, the testcase can be designed based on index so that your solution exceeed time limit.
you can find more about it on https://codeforces.net/blog/entry/101817 (thanks to robostac who shared that blog)
One of the fix mentioned in that blog which can prevent others from hacking your solution was wrapping hashmap key
you can use what I use in my template https://github.com/RedHeadphone/CP-template-python