I recently solved 743-D. This required me to create an adjacency list of size 2e5. So, I'd to create a vector
of vector
s, 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.
- 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,
Are there other ways to avoid heap usage? Is there something obvious that I'm missing?
Are there some easier and obvious ways to use the heap memory?
Any help regarding this is appreciated!
Here I added 3 characters to your MLE solution and got AC using ~32MB.
Facepalm. So, I was basically copying
al
the whole time. Ughh.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?
I usually assume the stack size is set to the problem's memory limit which is true in ICPC.
Okay. Thank you so much for your help!