TahsinArafat's blog

By TahsinArafat, history, 112 minutes ago, In English

During Codeforces Round 987 (Div. 2), I got Runtime Error on Test Case 59 (in Problem E. Penchick and Chloe's Trees). It shows Stack Overflow Error! But, the same code got AC on C++17 while upsolving!

  • C++20 Submission: 291655589 — Runtime Error on TC 59
  • C++23 Submission: 291671738 — Runtime Error on TC 61
  • C++17 Submission: 291671684 — AC

But, after a little modification on insider loop, it got AC in C++20: 291668944. But, I couldn't find any valid reason for stack-overflow, and how this submission solved this error!

Can you help me?

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

»
67 minutes ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

It is stack overflow. To compile C++23 solutions, Codeforces uses the following command: g++ -Wall -Wextra -Wconversion -static -DONLINE_JUDGE -Wl,--stack=268435456 -O2 -std=c++23 program.cpp -lstdc++exp -- it gives 256 MiB for stack. But for this program it is not enough. 450 MiB fixes the issue: 291681903. I'd say that on a 32-bit architecture, the pointer consumes less memory, which is why there is enough stack.

  • »
    »
    47 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks!

    But, what's about the modified code I've mentioned in the post? That code got AC on C++20, with no large change in code!

    • »
      »
      »
      45 minutes ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      You made mp and perm global, it reduced stack memory consumption.