Silly and preventable causes of WA

Revision en1, by robot-dreams, 2019-02-22 22:13:27

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
  • Using 1 << k instead of 1LL << k when the result won't fit in 32 bits

  • Only 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)
  • Using the wrong parameter (e.g. n instead of m) 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?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English robot-dreams 2019-02-22 22:13:27 1227 Initial revision (published)