Блог пользователя M4357R0

Автор M4357R0, история, 8 месяцев назад, По-английски

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?

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by M4357R0 (previous revision, new revision, compare).

»
8 месяцев назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

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.

  • »
    »
    8 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    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

    • »
      »
      »
      8 месяцев назад, скрыть # ^ |
      ← Rev. 3  
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.

»
8 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

well done