I got MLE in [this submission](https://codeforces.net/contest/1988/submission/272621807).↵
After investigation it turned out that I created empty containers before a recursive call (in the get_delete_x_ans function), resulting in creation of many such containers when call stack is deep.↵
↵
That sounds reasonable, but when I did the calculation, it seemed impossible that this mistake could lead to MLE when the mem limit is 512MB.↵
↵
So the calculation goes:↵
↵
My later accepted solution uses 175100KB, limit is ~524288KB, difference is 300000+KB = approx. 300MB.↵
↵
So it means that the submission above created empty containers that take up 300MB space.↵
↵
It will create 2 empty queue<int>, each is 48 byte on a 64-bit machine.↵
↵
Recursion depth is <=500000 from problem description.↵
So total space of empty containers is 2 x 48B x 500000 = approx. 5x10^7 B = 50MB.↵
↵
That's much less than 300MB, so if the calculation was correct, I shouldn't get MLE.↵
↵
Can someone help point out what's wrong with my calculation above? Thanks!
After investigation it turned out that I created empty containers before a recursive call (in the get_delete_x_ans function), resulting in creation of many such containers when call stack is deep.↵
↵
That sounds reasonable, but when I did the calculation, it seemed impossible that this mistake could lead to MLE when the mem limit is 512MB.↵
↵
So the calculation goes:↵
↵
My later accepted solution uses 175100KB, limit is ~524288KB, difference is 300000+KB = approx. 300MB.↵
↵
So it means that the submission above created empty containers that take up 300MB space.↵
↵
It will create 2 empty queue<int>, each is 48 byte on a 64-bit machine.↵
↵
Recursion depth is <=500000 from problem description.↵
So total space of empty containers is 2 x 48B x 500000 = approx. 5x10^7 B = 50MB.↵
↵
That's much less than 300MB, so if the calculation was correct, I shouldn't get MLE.↵
↵
Can someone help point out what's wrong with my calculation above? Thanks!