I get Memory Limit Exceeded for the DP solution to the Dole Out Cadbury problem in MockVita 2.

The problem statement and my solution are both in this link: https://ide.geeksforgeeks.org/7VTbiwLmU1

The idea is that two rectangles of the same proportion give out the same number of asked squares, so I every time I need the squares for a rectangle of a particular proportion - I look for it in the dictionary, if not found I will calculate and store it for later access.

Classic DP solution, yet it gives Memory Limit Exceeded.

Please point out the whether the flaw is in program logic or the Dp approach.

Thank you.