jeqcho's blog

By jeqcho, history, 4 years ago, In English

I have been using endl for competitive programming until now. For 350C - Бомбы, 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.

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Reason for that is, on using endl output gets flushed each time whereas with \n there is no such obligation.