abhinavsingh15682's blog

By abhinavsingh15682, history, 3 years ago, In English

While solving 1612C - Chat Ban I found something weird. I have submitted same code with C++14 and C++17,C++20. But it only was accepted with C++17.

C++14 :158761775

C++17 :158762654

C++20 :158762172

I tried to look for the reason online but could not find any.

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

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

contact your local exorcist asap

»
3 years ago, # |
  Vote: I like it -13 Vote: I do not like it

https://codeforces.net/contest/1612/submission/158779409

compare your solution with this modified solution of yours you will get it

or simply k*(k+1)/2 is not equal to (k*(k+1))/2

so in your code k*(k+1)/2 will give correct result if $$$k$$$ is $$$odd$$$ else it will give one less value then expected

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    i tried this code in custom test and it gives the correct result even if k is even.

    Spoiler
  • »
    »
    3 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    I don`t think it`s the reason because the order of operator is defined in the standard of c++.

»
3 years ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

i think it is because of precision issues, i fixed it by adding (long double) inside the sqrt function: 158781091