ClosetNarcissist's blog

By ClosetNarcissist, history, 12 months ago, In English

So I was solving this problem https://mirror.codeforces.com/gym/105723/problem/F

and wrote this solution https://ideone.com/SNfGJ6

It works fine in my laptop and ideone C++ 14 but when I submitted it in C++17 (GCC 7-32) I got WA on test 1. It did not make sense to me how I got a vastly different result on the test case in my laptop and CF. I suspected some type of RTE but I could not find any. Then I just submitted in C++23 (GCC 14-64, msys2) and got AC even though I did not change anything in the code.

Anyone knows why this happened. I feel like knowing it would kind of help me avoid it in contests. idk -_-

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
12 months ago, hide # |
 
Vote: I like it +13 Vote: I do not like it

I suspect this has something to do with floating point precision error. G++23 has a 64 bit judge, therefore the floats are more accurately represented. Try to avoid floats as much as possible if you can

  • »
    »
    12 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I also suspected something similar but it got the right answer in C++14 on ideone, which was 261798.698746. But C++17 on CF got me 361929.351562. It's insane how much the precision error blew up if that's the case.

    • »
      »
      »
      12 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      The thing is that with c++17 you get inside the if (rt > rb) but with c++20 you don't

      Comparing doubles with some eps value could help probably

      • »
        »
        »
        »
        12 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Damn how did i miss that. I added precision handling on the if(len <= ab) statement later but completely forgot about the other if statement. Thanks