n_k101's blog

By n_k101, history, 3 years ago, In English

After using Binary search in Problem C(Round 1574) I am getting TLE I don't know where it is getting out of bounds, please help

code link- https://mirror.codeforces.com/contest/1574/submission/181236065

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

| Write comment?
»
3 years ago, hide # |
Rev. 3  
Vote: I like it +3 Vote: I do not like it

Your code seems fine speed-wise (it might give Wrong Answer), it's probably slow I/O.

You can add this at the beginning of your code for faster IO.

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ...

}

Just be careful that if you use this, you should stick with cin/cout and not mix it with scanf/print/puts since they use different buffers and the order read/written will be all mixed as well.

  • »
    »
    3 years ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it

    Thank you so much You are a saviour, it worked

    That's why I love CP everytime I get to learn something new and amazing community of people ready to help

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

    Thank you so much!! This also helped me. :)

»
3 years ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Use C++20 instead of C++14 and Fast I/O