AtulMishra0740's blog

By AtulMishra0740, history, 2 months ago, In English

I have noted a glitch in the codeforces compiler leading to my failed on main test cases verdict. In the question B of this contest, whose link is this, my solution which passed on pretests is this

After running on main tests , it showed wrong answer on main tests 11 .

I checked the error and found it is giving wrong answer in this test case : 77921270569329490 377318254283917957 Its correct output is : 1005355647 while my code on codeforces compiler gave the output : 1005355648

I copied my code and ran it on every online compiler I know as well as my local compiler and everywhere it gave the correct answer, while in codeforces inbuilt compiler it gave wrong answer.

I tried to dig further in it and found that it is not even printing the square root of 77921270569329490 correctly (which is 279143817, but its giving 279143816), which is taken care in all other compilers.

This glitch lead my answer to fail in main test cases.

If the moderator is viewing this, please check my submission on different compiler or do something about it. I do not want my rating to go down for no reason while it could have gone up.

 
 
 
 
  • Vote: I like it
  • -16
  • Vote: I do not like it

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

This link might be helpful.

Edit: Link to AC version of your code (I just replaced sqrt with sqrtl). One more problem that you would like to try(it is the same problem which taught me the difference between sqrt and sqrtl).

»
2 months ago, # |
  Vote: I like it +1 Vote: I do not like it

same, in vs code its giving correct but in codeforces it got wrong.

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

now i will always write

#define sqrt(x) sqrtl(x)
»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I can feel your pain, I also got WA on main testcases.

»
2 months ago, # |
  Vote: I like it +10 Vote: I do not like it

I copied my code and ran it on every online compiler I know as well as my local compiler and everywhere it gave the correct answer, while in codeforces inbuilt compiler it gave wrong answer.

The compiler you are currently using on codeforces is a 32 bit compiler. I'm guessing all of the other compilers you've tried are 64 bit. Floating point numbers work very differently in 32 bit vs 64 bit. If you wanna know more about how it works, I have written a blog about it in the past.

Just to show you how weird floating point numbers can be using a 32 bit compiler. This code (175284859) is equivivalent to your current submission, getting WA on test case 11:

        double rootl = sqrt(l);
        ll x = rootl;
        double rootr = sqrt(r);
        ll y = rootr;

Now if you just add a couple of completely useless calculations inbetween (175284899)

        double rootl = sqrt(l);
        pow(rootl, 10);
        ll x = rootl;
        double rootr = sqrt(r);
        pow(rootr, 10);
        ll y = rootr;

the submission now gets WA on test case 4 instead of 11. (However, it correctly says that the sqrt(77921270569329490) is 279143817 =p)

A good thing to remember for the future is to avoid using 32 bit compilers if you are working with floating point numbers.