Question Link In this problem, I initially implemented a DP solution by defining the state and transition. However, it resulted in a "Memory Limit Exceeded" error. Surprisingly, when I simply interchanged the row and column while keeping the logic, states, and transitions the same, the solution was accepted.
Can someone explain why this happened?
You can see the Accepted Submission
Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).
Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).
Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).
The reason is that vector needs to store some extra information, so just a vector without elements takes some memory.
The exact memory usage of an empty vector is implementation-dependent, but usually it's 24 bytes (64bit compiler, 3 pointers)
So for your AC solution we have around
((n + 1) * 8 + 24) * 2 + 24 = 160000088
bytes and for MLE solution around(2 * 8 + 24) * (n + 1) + 24 = 400000064
which is 2.5 times more