mcGyver's blog

By mcGyver, history, 4 years ago, In English

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

  • Vote: I like it
  • +11
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

It's a memory stack size issue. I had a similar problem here https://codeforces.me/blog/entry/68870

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    But I have already declared the arrays globally still this happened. Taking arrays globally seems not working in this case..

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It's the recursion. Recursion calls eat up stack memory too.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        What should I do then.. Is there any way around to get rid of this?

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          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.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +9 Vote: I do not like it

            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.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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