tirupati's blog

By tirupati, history, 9 years ago, In English

I was solving this problem today and I get a time limit exceeded verdict even though the time limit specified is 5s and the solution is O(n) and given bounds of n is 1<=n<=10^6. The problem can be found here and solution here.

Thank You

PS: Is there a problem with the judge?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try fast cin, cout.

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

    Thank you I got AC using fast i/o. Can you tell me why this (std::ios::sync_with_stdio(false);) speeds up input/output also when should we use fast i/o. ( I mean what is the maximum order of data read or written using cin/cout without fast cin/cout).

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

    in MinGW build used by codeforces printf/scanf is much faster than cin/cout even if you'll add sync_with_stdio etc. Tried printing 106 integers in custom test:

    cout — 514 ms
    cout with sync_with_stdio(false) — 467 ms
    printf — 202 ms