Click here for Problem Statement
SIGSEGV Error is Irritating me a lot . Please help me overcome this problem !
What Should I do to Overcome this SIGSEGV Error. I had allocated memory correctly but still it shows this error
P.S.: My First D.P.
THANKS A LOT IN ADVANCE
#include< iostream >
using namespace std;
long long int mem,temp;
long long int f(long long int x)
long long int n,i;
for ( i = 0 ; i < 1000001 ; i++ )
mem [ i ] = 0;
while ( cin >> n )
cout << max(n,f(n));
cout << endl;
you are accessing the array mem out of bound , mem array is of 10^6 size , whereas n can be upto 10^9 ,
@vsukeeshbabu, value of n can be upto 10^9, so you cannot create an array that big. Also, do not need to memoize for ALL values less than n, so in order to only store those values you require, and quickly and conveniently access them in logarithmic time, you can use a map. A map behaves like a function. You give an input to it, and it gives a required output. It is stored in the form of a heap, so it can be updated and queried in logn time. Click here and here for map reference. You can use it just like an array.
thanks Vaibhav @gvaibhav21 !!