I don't think anybody likes getting WA. It's especially annoying when they're silly issues that are easy to prevent in the future, so I decided to keep start keeping track of things that have caused me to get WA. Here are a few:
Not setting precision high enough when using
cout
to print floating point answers- The default precision is only 6 digits, and problems often ask for more precision than that, so I think it's a good idea to do
cout << setprecision(12)
whenever floating points are involved
- The default precision is only 6 digits, and problems often ask for more precision than that, so I think it's a good idea to do
Using
1 << k
instead of1LL << k
when the result won't fit in 32 bitsOnly considering one direction of an undirected graph when reading input
Using the wrong priority queue ordering
- Since C++ priority queues give you the max element by default, you need to initialize with
priority_queue<T, vector<T>, greater<T>>
if you want to get the min (e.g. in Dijkstra's algorithm)
- Since C++ priority queues give you the max element by default, you need to initialize with
Using the wrong parameter (e.g.
n
instead ofm
) when reading input(!)- I'm not joking, this has caused me to pass pretests but fail system tests before :(
What about you, what are some of the (silly and easily preventable) causes of WA that you've encountered?