Блог пользователя mcGyver

Автор mcGyver, история, 3 года назад, По-английски

I was solving this 520B - Две кнопки 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
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

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

        • »
          »
          »
          »
          »
          3 года назад, # ^ |
            Проголосовать: нравится 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.

          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
              Проголосовать: нравится +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.

»
3 года назад, # |
  Проголосовать: нравится 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.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 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