Why is this solution at least 4 times slower when using recursion?

Правка en1, от JasonMendoza2008, 2024-08-14 23:06:08

Consider this problem (https://codeforces.me/contest/984/problem/D).

Solution one (https://codeforces.me/contest/984/submission/276446617) uses two recursive functions (compute_f, and compute_max_xor) that use unordered_map for memoization. It does not pass (2000 ms TLE).

Solution two (https://codeforces.me/contest/984/submission/276446798) is the same from a logic point of view, except it uses Dynamic Programming. It passes in 546 ms.

I thought it could be because of hash collision some people have added to hack some other people but adding a random custom_hash did not help whatsoever.

Does the overhead of using an unordered_map that HIGH? Big enough to bring a x4 in time? Or am I missing something else?

Thank you!

Теги dp, tle, question, help me

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский JasonMendoza2008 2024-08-15 16:53:56 182
en5 Английский JasonMendoza2008 2024-08-14 23:20:27 4 Tiny change: 'oever.\n\nDoes the over' -> 'oever.\n\nIs the over'
en4 Английский JasonMendoza2008 2024-08-14 23:08:31 2 Tiny change: 'could be tjat differe' -> 'could be that differe'
en3 Английский JasonMendoza2008 2024-08-14 23:08:18 82
en2 Английский JasonMendoza2008 2024-08-14 23:07:35 89
en1 Английский JasonMendoza2008 2024-08-14 23:06:08 810 Initial revision (published)