0-jij-0's blog

By 0-jij-0, 5 years ago, In English

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!

  • Vote: I like it
  • +10
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +59 Vote: I do not like it

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

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it -7 Vote: I do not like it

      #define endl '\n'

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +39 Vote: I do not like it

        Good bye interactive problems...

    • »
      »
      »
      5 years ago, # ^ |
      Rev. 2   Vote: I like it +33 Vote: I do not like it
      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

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Ah okay got it. Thank you for your help!