I was solving this 520B - Two Buttons problem. Here maximum input and output size is 10^4. In my code I took N = 10^6 and it was giving Runtime Errorin my local IDE but when I submitted the same code, it got accepted. My submission 116080580. I dont know whether it's a fault of my device or the compliler I am using. Can anyone help??
It's a memory stack size issue. I had a similar problem here https://codeforces.me/blog/entry/68870
But I have already declared the arrays globally still this happened. Taking arrays globally seems not working in this case..
It's the recursion. Recursion calls eat up stack memory too.
What should I do then.. Is there any way around to get rid of this?
To make it work on your local machine look up the build option to increase your stack size or how to increase the stack size in your ide.
To reduce your program's memory footprint in general, use iterarive dp if possible. A more laborious way is maybe simulate recursion using stack, but you'll rarely need to do this.
In practice recursive DFS works faster than non-recursive DFS. I have no idea why it's so but I've stumbled upon this problem several times.
This is clearly a problem with stack size, but it's difficult to help without knowing what OS are you using. If you're using Linux, you can disable stack limit using
ulimit -s unlimited
.My OS is windows 10. I dont find any similar method for windows like Linux has but there is a setting in CodeBlocks IDE which can increase the stack size. But it is only restricted to CodeBlocks. Usually I use sublime text 3 and for that things are same as before... RTE