Hey everyone,
I ran into something weird. I have a solution that
TLE on g++17 : 367366805
Accepted on g++23 : 367366517
Honestly, it feels a bit unfair that the exact same solution works on one compiler and not the other. I only found out about this by luck, I could’ve wasted so much time trying to come up with another solution, while mine is already correct.
Has anyone else experienced this? Any idea why the compiler version makes such a difference?








Auto comment: topic has been updated by M4357R0 (previous revision, new revision, compare).
It's caused by std::unordered_map/set hacks, but the problem's test cases doesn't include edge cases affecting g++23 since the compiler was added later than the problem.
the only thing that seems to make it work in g++17 was to fix the map size to 5000
but i'm still not sure why
As I know, unordered_map's hash function depends on the size of the map. (A prime number or a power of two) If there is a hack targeting the normal hash function, it won't affect you when you fix the map size. That's what I think. You can check custom hashing if you're interested.
well done