Блог пользователя checkMate09

Автор checkMate09, история, 8 лет назад, По-английски

Hey codeforces , I was solving C. Replacement. my first submission got Accepted with awful time 1996 ms -> My first Submission
so i was looking to reduce it once using cin.tie and it doesn't work cin.tie(0) submission another way that i tried is to use scanf instead of cin and the code didn't output even sample answers correctly. and here is the strangest thing that i re-send the accepted code it gives TLE now!! so, any coding technique to reduce the time? why is my cin.tie submission Run time error? why my identical accepted submission got TLE ? Thanks.

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

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

Never use scanf with cin.tie(0). Source

AC with cin.tie(0)

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

    thank you for your reply instead of throwing negative votes. and for your help accepted with reduced time 1652 ms still awful :D (y)

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

      Welcome. :)

      Same code with scanf and printf(171ms).

      Code

      PS — I am too surprised of this huge difference!

      PPS — Nope, now I am not. :-P You used endl which is slow. Code (436ms).

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

The problem is not the use of cin/cout, but rather the use of endl. It is not just a simple newline character. It also flushesh the whole stream which causes bad performance. Try using '\n' instead of endl in such problems where there are many lines of output