Performance of endl vs \n

Revision en1, by jeqcho, 2020-05-08 11:53:51

I have been using endl for competitive programming until now. For 350C - Bombs, both 79359924 and 79360060 have the same time complexity of $$$O(n \log{n})$$$, but the first gets TLE while the second gets AC. The reason is that the AC solution uses \n instead of endl. The difference in performance is significant because this problem requires $$$6\times 10^5+1$$$ lines of output at most!

Conclusion: Use endl only if it is a query problem.

Tags performance, c++, #tle

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English jeqcho 2020-05-08 11:53:51 498 Initial revision (published)