How is the 256MB memory divided amongst the stack and the heap for questions and more questions

Revision en1, by Mooncrater, 2019-07-14 09:18:08

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!

Tags #memory, #heap, stack memory

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Mooncrater 2019-07-14 09:18:08 1170 Initial revision (published)