Fourty_Seven's blog

By Fourty_Seven, 3 years ago, In English

Until today I thought that recursion in general is very bad for competitive programming and it always fails, but now it looks like that it was python hogging memory all this time in my previous recursion solutions. I was solving this problem, C of the last contest, and my solution was getting runtime error due to memory so I tried to optimize it the best I can but it was still not working so I tried what every python programmer here have to do sometime or other, I copied my solution gave it to chatGPT to convert to c++ (which it surprisingly did in the first try). AND IT WORKS. Even my previous less optimized versions work in c++.

< sobbing >

Now I just want to know if it was me or python because at this point I have no trust in either of them. Someone please look into my solution and tell me if I am doing something wrong or recursion is just impossible with python here. My approach is basically the same as mentioned in the editorial, I am just using recursion for dfs. In worst case my program should have a recursion stack of $$$10^5$$$ with each item of constant size so I am very confused why is it using so much memory. Considering 512MB limit there should be more than 5KB per stack element, how are 10 integers taking 5 KiloBytes of space.

One last thing, is there a difference between these two errors:

Memory limit exceeded

exit code: -1073741571 (STATUS_STACK_OVERFLOW)

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it