Hello Codeforces!
We’ve all been there: your logic is perfect, but the judge gives you a "Compilation Error" or a mysterious "Runtime Error." Today, I want to break down the most common mistakes and how to fix them quickly during a contest.
1. Compilation Error: The "Header" Headache
Why it happens: Using functions without the right library or using non-standard headers. The Fix: Use #include <bits/stdc++.h>. It includes almost everything. If you are on macOS and it fails, ensure your compiler paths are set or use specific headers like , , and .
2. Runtime Error: Out of Bounds
Why it happens: Accessing a[n] when the array size is n. The Fix: Always declare your arrays slightly larger than the limit (e.g., int arr[N + 5]). Also, check your loops: for(int i = 0; i <= n; i++) is a common culprit if the index is 0-based.
3. Runtime Error: Stack Overflow
Why it happens: Deep recursion (like DFS on a large tree) can crash the stack. The Fix: - Increase the stack size in your compiler settings. - Rewrite the logic using an iterative approach with a std::stack. - For C++ users, use vector instead of large local arrays inside recursive functions.
4. The Famous "Floating Point Exception"
Why it happens: This almost always means a division by zero or a modulo by zero. The Fix: Double-check your % and / operations. Ensure the denominator isn't zero, especially in math-heavy problems or when calculating averages.
5. Integer Overflow
Why it happens: Using int for values that exceed (2*10^9). The Fix: Use long long for everything if you are unsure. A common trick is to use #define int long long at the top of your code (though be careful with memory limits!).
I hope this helps some of you avoid those painful penalties! What is the most annoying bug you've ever spent hours fixing? Let’s discuss in the comments!



