Блог пользователя 0-jij-0

Автор 0-jij-0, 4 года назад, По-английски

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!

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +59 Проголосовать: не нравится

ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); does not stop endl from flushing

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Ah okay thank you but then what does it do exactly?

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится -7 Проголосовать: не нравится

      #define endl '\n'

    • »
      »
      »
      4 года назад, # ^ |
      Rev. 2   Проголосовать: нравится +33 Проголосовать: не нравится
      1. 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.
      2. cin.tie(0) makes cin not tied to cout. If cin is tied to cout, it will flush every time you cout something

      upd: you may found this helpful