In today’s Div. 2 contest, I encountered a frustrating issue that taught me the importance of precision in competitive programming.
The problem logic seemed straightforward: identify odd perfect squares. Confidently, I implemented the logic in my code editor (VS Code), tested a few cases locally, and it seemed flawless. However, when I submitted the solution during the contest, it gave Wrong Answer on Test 1 repeatedly. Problem:
I couldn’t accept that such an easy problem was slipping away. Frustration kicked in as I spent over 40 minutes debugging and even tried different C++ standards like C++17, C++20, and C++23, only to face the same result: Wrong Answer on Test 1. Disheartened, I shifted my focus to solving other problems, managing to complete Question B and Question C before circling back with just 30 minutes remaining.
After some reflection and experimenting, I finally pinpointed the issue:
It turns out that floating-point arithmetic caused the issue. sqrt(n) * sqrt(n) does not always yield exact results due to precision errors in floating-point operations.
I replaced it with a safer and integer-based alternative:
This resolved the issue instantly, but by then, the damage was done. The time lost on debugging and the rank I could have earned were irrecoverable.
I hope whoever reads this avoids such a mistake in the future.