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

Автор Mooncrater, история, 5 лет назад, По-английски

I recently solved 743-D. This required me to create an adjacency list of size 2e5. So, I'd to create a vector of vectors, i.e vector<vector<int>>. If one checks the size of a vector<int> variable, then we'll get 24 bytes. So, $$$4.8 \times 10^6$$$ bytes = 4.8MB. The question clearly mentions that we're given a total of 256 MBs. So the problem here might be that the stack size is smaller than 4.8 MB.

  1. So, What is the stack size, and the heap size?

My solution, that used this approach got an MLE (memory limit exceeded).

So, I decided to use the heap memory instead, (by using the new keyword). Here is the submission. The code is obviously harder and less clear. So,

  1. Are there other ways to avoid heap usage? Is there something obvious that I'm missing?

  2. Are there some easier and obvious ways to use the heap memory?

Any help regarding this is appreciated!

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

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

Here I added 3 characters to your MLE solution and got AC using ~32MB.

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

    Facepalm. So, I was basically copying al the whole time. Ughh.

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

    So, there is no such case when one has to use heap memory instead of the stack memory? (Not including dynamic memory allocation). And is the 256MB all stack memory?