In competitive programming, we often use map or unordered_map. However, choosing the wrong container can sometimes cause our code to hit a Time Limit Exceeded (TLE). Today, I will share with you why the unordered_map get TLE ?
1.Hash collisions → Worst case O(n) instead of O(1). 2.Adversarial inputs → Test cases designed to break default hash. 3.String hashing cost → Large strings slow down lookups. 4.Higher constants → More memory & overhead than map.
https://mirror.codeforces.com/problemset/problem/2131/C
In this problem, using unordered_map in the same code will lead to a TLE, whereas replacing it with map in the exact same scenario will result in an Accepted verdict.
So always use a custom hash if you don't want to get blown up.









You can refer to this blog for a better custom hash function