Блог пользователя ilove_sundarKanya

Автор ilove_sundarKanya, история, 6 часов назад, По-английски

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

Memory Limit Exceeded Submission

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).

»
6 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).

»
6 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ilove_sundarKanya (previous revision, new revision, compare).

»
23 минуты назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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