### mcGyver's blog

By mcGyver, history, 5 weeks ago,

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??

• +11

 » 5 weeks ago, # |   0 It's a memory stack size issue. I had a similar problem here https://codeforces.com/blog/entry/68870
•  » » 5 weeks ago, # ^ | ← Rev. 2 →   0 But I have already declared the arrays globally still this happened. Taking arrays globally seems not working in this case..
•  » » » 5 weeks ago, # ^ |   0 It's the recursion. Recursion calls eat up stack memory too.
•  » » » » 5 weeks ago, # ^ |   0 What should I do then.. Is there any way around to get rid of this?
•  » » » » » 5 weeks ago, # ^ |   0 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.
•  » » » » » » 5 weeks ago, # ^ |   +9 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.
 » 5 weeks ago, # |   0 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.
•  » » 5 weeks ago, # ^ |   -11 The default stack size for my Linux machine seems to be a couple of MBs, while certain problems on CodeForces require memory sizes well above that. People are bound to face this issue once they start solving Div. 2 Bs/Cs. Considering the number of new users who are registering every month, can links to blogs on this along with those to blogs on other important stuff such as Modular Arithmetic basics (Fermat's Little Theorem) be added to a single 'pinned' blog?
•  » » 5 weeks ago, # ^ |   0 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