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?
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.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!
You made
mp
andperm
global, it reduced stack memory consumption.