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

Автор Dark_Knight_3, история, 2 года назад, По-английски

In the recent Codeforces Round 976 (Div. 2) and Divide By Zero 9.0 contest, I submitted my solution for 2020B - Brightness Begins in C++ 23. There, I got the wrong answer on G++ 23, but after the contest, I solved it by changing the language to G++ 17, and it got accepted. So what was the problem? Should I be using G++ 17 or G++ 23? What should be considered when using the built-in sqrt() function? Like precision, etc.. G++ 17 solution 283662762 G++ 23 solution 283597439

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

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

Auto comment: topic has been updated by Dark_Knight_3 (previous revision, new revision, compare).

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

Auto comment: topic has been updated by Dark_Knight_3 (previous revision, new revision, compare).

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

You should be using either sqrtl or binary search.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

sqrt() uses floating point, so its not "reliable". Use floating point in CP as less as you can. Use binary search.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Actually when you need precise answer for large inputs always go for sqrtl instead of sqrt because sqrt returns a floating interger where as sqrtl returns value in double which has more accuracy than float so using sqrtl is always a better choice irrespective of compiler(But compilers do make significant difference in TC)..Hope this helps

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

I made a blog about why not to use C++ 17 Here

If some problems work only in C++ 20 / C++ 23 and some other Problems work only in C++ 17, we need a fix for this problem.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

I usually write a custom function to fix this and it works all the time ¯_(ツ)_/¯

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