My program is giving runtime error when i exceed my array size beyond 10^7 , can anyone help me to solve this issue
Then you should find another algorithm for the problem. You may consider the following things:
-
The array of size 10^9 takes 100 times more memory than 10^7 size array. Considering it an int array, this array alone will take memory of around 3800MB. Most problems do not allow this amount of memory.
-
Even if you’re able to declare an array of such great size, You won’t be able to apply a linear time algorithm in many of the problems as it will probably exceed the time limit.
-
To get a hint of the approach, you can look at other solutions’ memory and execution time.
-
If the required array in the problem requires such an array, but it would be sparsely filled, then you may consider hashing.
If it is a contest problem, remove the solution link as soon as possible!
As for the approach, you’ll find much smarter solutions, once the contest ends. (:
Declare array as global i.e. before int main().
Got ur idea i ll try finding some other approach
In your situation, point number 3 will surely help you out
i think you are trying to solve EGRKAKE…you can do it with very simple trick…now recognize that TRICK by your self
okk @ xariniov9
i found others are also doing the same mistake and got 25 points but in next 4 minutes they got 100 points , how can they do this
Got it complexity will be O(1)