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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 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