n_k101's blog

By n_k101, history, 2 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://codeforces.me/contest/1574/submission/181236065

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

| Write comment?
»
2 years ago, # |
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.

  • »
    »
    2 years ago, # ^ |
      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

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

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

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

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

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

    are you saying that if one uses C++20 he doesn't need to add these?

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

    If yes can you show some documentation?

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

      It seems like there's no difference at all. Submission link with copypasted code of op, but with C++20 enabled: 181341327

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

      No but C++20 is comparatively faster than C++14