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

Автор n_k101, история, 21 месяц назад, По-английски

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.com/contest/1574/submission/181236065

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

»
21 месяц назад, # |
Rev. 3   Проголосовать: нравится +3 Проголосовать: не нравится

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.

  • »
    »
    21 месяц назад, # ^ |
      Проголосовать: нравится +6 Проголосовать: не нравится

    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

  • »
    »
    21 месяц назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

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

»
21 месяц назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    21 месяц назад, # ^ |
      Проголосовать: нравится +9 Проголосовать: не нравится

    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?