i was practicing this question https://www.codechef.com/problems/COPR16G/ and i found that endl gives TLE but \n doesnot why? is it because endl is flushing after giving a newline?
i was practicing this question https://www.codechef.com/problems/COPR16G/ and i found that endl gives TLE but \n doesnot why? is it because endl is flushing after giving a newline?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3611 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | dXqwq | 3436 |
| 8 | Radewoosh | 3415 |
| 9 | Otomachi_Una | 3413 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 163 |
| 2 | adamant | 149 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 135 |
| 7 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 132 |
| Name |
|---|



cout << endl;is the same ascout << "\n" << flush;. Flushing a buffer is very slow, because if you output just a small string, it's something like 1 flush per 10 characters, and if you letcoutdo the buffering automatically, it's something like 1 flush per several thousand characters. That's why the runtime is so different.ooh thanks i didnt faced it till now so i thought maybe i went mad :D
Just curious, what gave you the motivation to change all endl to "\n"? Or did you try all other stuff but still got tle?
define endl "\n"
you can use this in your template
And then you might get ILE in an Iterative Problem =)
well then you can just comment the
definelinethe advantage of this is that you don't have to switch between
endland'\n'all the time, you can just comfortably useendland comment thedefineline when necessaryAnd then you might get TLE in an Iterative Problem =)
mou, nii, that's not fun >:(
you have to flush the buffer when printing outputs for interactive problems anyway, so solutions with
endlshould pass, it won't make sense otherwise