Competitive Programming Guides

Various resources

Online Judges

Learning Resources

Books

Websites

Youtube Channels

Chinese Resources

IOI-Style Contests Hints

Debugging Wrong Answer

Debugging Time/Memory Limit

  1. Calculate the exact time complexity of your code (Online Judges can handle ~$10^8$ complexity in 1 second)
  2. Calculate the exact memory complexity of your code and calculate memory limit in bytes
  3. Calculate the exact amount of interactions in your code (if the problem is interactive)
  4. Try to balance time & memory in the code
  5. Use bitset instead of boolean array to optimize memory
  6. Use fast i/o (ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) in C++) and replace endl with '\n'
  7. Add/Remove depending on system (32/64) #define int long long
  8. Use map instead of unordered_map, (Or vice-versa)
  9. Use set instead of unordered_set, (Or vice-versa)
  10. Compress the numbers (i.e. Distinct Values Queries)
  11. Use array to count the frequencies instead of map
  12. sqrt takes long time, So use this i*i <= n is more effecient than i <= sqrt(n)
  13. Optimize your seive from $O(N * \log_2{N})$ to $O(N * \log_2{\log_2{N}})$
  14. Don't clear the arrays & data-structures if there is no testcases
  15. Use array of sets instead of defining a set everytime
  16. Use memoization in recursion as much as possible
  17. Convert a recursive DP to an iterative DP
  18. Use break, continue, goto, and return as much as you could
  19. Use Porgan Princible (in 2SUM, you should add to the map while trying to find, not before)
  20. Use small-to-large decomposition (in trees or in DSU)
  21. Optimize memory in DP
  22. In finding shortest route path, put a matrix tells you were you came from, then roll back
  23. When rolling back to find a path, use a while instead of recursion
  24. In binary exponintiation, use while instead of recursion
  25. Write const in constant variables (i.e. MOD), because the compiler calculate it faster
  26. Write/Remove inline in functions that you are using
  27. In segment trees, building is faster than updating every element
  28. Pass parameters by reference if you can
  29. In DSU, use path compression + order by rank (small to large) optimizations, so your code runs in $O(\alpha(N))$
  30. Try different versions of the language (i.e. G++17, G++20, Clang20)
  31. If your code gets TLE on the edge, resubmitting the code may work
  32. If the solution of the problem is one of the subarrays, try to think how to convert it to two-pointers
  33. You may precalculate (hardcode) some values on local device and put them in your submission to optimize it
  34. You may use #pragma so read vectorization guide, don't put it in your template, it may cause RTE in some online judges other than SOJ
  35. If non of these above worked, probably your algorithm is bad