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

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

Hello mates. In the recently finished contest, regarding problem B Ela's Fitness and the Luxury Number,I submitted it using cpp 20 64-bit compiler, I got 4 WA verdicts which had cost me a lot of penalty till I solved it(pure coincidence as I tried int128 instead of ll then knew from the compiler error that type-casting is the problem so type-casted the sqrt() argument into long double and AC)

After the contest, I looked over the submissions and saw that many got it AC by cpp 17 compiler so tried my EXACT WA4 code ,but changing the compiler from cpp20 to cpp17. Magically, the same exact code was AC by cpp 17. I concluded the issue is with cpp 20's sqrt() fn, its argument should be type-casted to long double or rather use sqrtl(), but I wanna elaboration on why that happened and how not to fall in that on next contests ?? Here are my submissions: 175013082 The one Finally AC during contest after 10 tries, 175001140 WA pretest 4, 175043791 same WA4 code but AC by cpp17

UPD: It was really a well prepared contest that it rose awareness to avoid using built_in functions like sqrt() or even sqrtl() as they depend on floating pt calculation, I found this blog which is an absolute gem discussing the alternatives to those fns.

I tried implementing sqrt()fn myself using binary search returning an integer as in 175151224 and indeed got AC by cpp20 without any further type-casting avoiding any precision errors. Its complexity is logarithmic and accuracy is guaranteed.

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

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

Hey , I have checked for the square root https://mirror.codeforces.com/contest/1737/submission/175044526 it is giving AC in sqrtl and it is giving WA https://mirror.codeforces.com/contest/1737/submission/175047080 What is The difference ??

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

    Precision issues. sqrtl() deals with the argument as long double. On the other hand, sqrt() deals with it as double, so precision is important for an accurate answer Mine worked with sqrt() in cpp20 because i type casted the argument into long double which is equivalent to using sqrtl(), the weird part is that the code with sqrt() and no type casting was ACC normally by cpp 17, but WA for cpp20, so it was pure luck that some people got it AC from first try and some kept getting WA4 !

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

Yeah, I fixed the same C++20 code link

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