I am doing 1066A - Vova and Train and I am using Gvim. Here is my source code below.
Code
It always says 'terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc shell returned 3
Need help! Thanks in advance! Don't know why the font is weird for my code.
Looks like it works when I run it through the sample test cases. Submission says Memory Limit Exceeded.
Can you send the link of submitted code because I think there are lots of errors in above code.
80174186 Thanks!
firstly using ll=long long is not right you should write #define ll long long instead.
I changed to #define ll long long but I am still getting Memory Limit exceeded. Here is the submission: 80174981
Your solution uses too much memory. In this loop:
you add $$$d / v$$$ values to your vector, but in the sample already, we have $$$d = 10^9$$$ and $$$v = 1$$$, so $$$d / v = 10^9$$$ which is too much. try finding a more efficient solution.
Btw.
using ll = long long
is not incorrect, but I wouldn't consider it as nice. I agree with ronak037 that#define ll long long
is much betterThanks!
"Memory limit exceeded" means you have used more memory than the given memory limit ($$$256$$$ megabytes). The reason being you are trying to store a lot of long long ints, $$$10^9$$$ in the worst case. Each long long int takes up 8 bytes. Hence, in the worse case, you are using $$$8*10^9$$$ bytes, or, $$$8000$$$ megabytes.
The exception
bad_alloc
is thrown when the program fails to allocate the requested memory space. You can read more about it here.You can not use this much memory at a time. Try to think of a better approach.
Thanks!