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

Автор abhinavsingh15682, история, 22 месяца назад, По-английски

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.

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

»
22 месяца назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

contact your local exorcist asap

»
22 месяца назад, # |
  Проголосовать: нравится -13 Проголосовать: не нравится

https://codeforces.com/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

  • »
    »
    22 месяца назад, # ^ |
      Проголосовать: нравится +5 Проголосовать: не нравится

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

    Spoiler
  • »
    »
    22 месяца назад, # ^ |
      Проголосовать: нравится +10 Проголосовать: не нравится

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

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

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