Hello everyone,
I've noticed in the last contest (Codeforces Round 632 (Div. 2)) many people including me had this issue in 1333D - Challenges in school №41 where our verdicts changed from TLE to AC by just changing every "endl" to '\n'.
TLE Submission: 75902058
AC Submission: 75903554
I knew before that "endl" does some flushing business and this usually takes (Maybe I'm wrong) time but I knew also that the following lines disable this thing: (Maybe I'm also wrong)
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
But I still got an issue using "endl" so can someone explain if possible how does endl work exactly and what do the lines above change about using cin/cout/endl?
Thank you!
ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
does not stopendl
from flushingAh okay thank you but then what does it do exactly?
scanf/printf is faster than cin/cout, but when you use ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);, it makes cin/cout faster,equivalent to speed of scanf/printf
#define endl '\n'
Good bye interactive problems...
Seems like your buffer of readed massages was flushed
ios::sync_with_stdio(0);
makes iostream not synchronized to stdio. You can not use cin and scanf at the same time after using it.cin.tie(0)
makes cin not tied to cout. If cin is tied to cout, it will flush every time you cout somethingupd: you may found this helpful
Ah okay got it. Thank you for your help!
This question has been answered like a thousand times.