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 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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?
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 letcout
do 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
define
linethe advantage of this is that you don't have to switch between
endl
and'\n'
all the time, you can just comfortably useendl
and comment thedefine
line 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
endl
should pass, it won't make sense otherwise