Can somebody help me debugging this code?



Hey guys!

I was trying to solve CHEFFA from August long. My thinking was same as others used, using table dp[index][x][y], but my code is not only failing on test cases, but also giving TLE. Similar codes have got a AC, so I am guessing I am at fault in implementation.

I will be really grateful if someone can point out my mistake, so that I can know where I erred. My code link-


I checked with many random inputs and all of them is giving correct answers. Can’t find the test case where it fails! But what I think is, it’s not best practice to use dynamic vectors in recursive functions. You should try to declare them globally and work with them. This dynamic vectors may be one of the reason you’re getting TLE.

This is my solution. I hope it helps you in some way.

link text


Got the reason for WA.

It was undefined behavior at input size of 1 due to non existence of vector element.


Yes, I did got AC after that fact. The problem is WA, not TLE. I can get that, since value of vector is copied, it can not only give TLE but also SIGSEV due to excess memory consumption…

But WA? :frowning: . I appreciate you taking your time out tho! :slight_smile:


just out of curosity, what was the problem?


Undefined behaviour. This thing is hell to debug, especially if undetected :frowning: