Tips and tricks to improve performance of your ACM solution
Here I gathered system-programming tricks that can improve performance of your solution in C++ dramatically!
- Use scanf/printf functions for standard IO instead of cin/cout
- Memory-align buffers and structures to WORD size of your architecture (4 bytes for 32-bit and 8 bytes for 64-bit)
- Use arrays instead of linked lists (to use memory block caching)
- Avoid “if” stamements in loops
- If-clause should contain code, which is more likely to execute (if-condition == true)
- Use inlining for short functions
- Use objects allocated on stack but not on heap (local objects for functions instead of allocated with malloc/new)
- Use pre-calculated hardcoded data (e.g. you can store first N prime numbers or first N Fibonacci numbers in order not to calculate them every time you need one)
Feel free to share!