Abrar535's blog

By Abrar535, history, 6 years ago, In English

On Educational Codeforces Round 43 Problem B this solution 37778558 in c++17 gives AC whereas this same solution 37798163 in c++14 gives WA, tried it with c++11 and c++ 5 also but giving WA only c++17 gives AC :/ Can anyone tell me why??

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

| Write comment?
»
6 years ago, # |
Rev. 5   Vote: I like it +12 Vote: I do not like it

row = ceil((k-n)/double(m-1));

First rule of float numbers: never use float numbers.

row = (k-n + (m-2)) / (m-1);

This gives accepted. http://codeforces.com/contest/976/submission/37799166

P.S. not sure why it gives AC in C++17. Better optimizatior, maybe.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you , i got it now , that case is not picking up all the precisions and so ceiling was not working there , so integer ceiling or using a long double instead of double gives AC. Thanks a lot , lesson learned :)

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 3   Vote: I like it +1 Vote: I do not like it

      I actually wasn't exaggerating: never use double unless it's printf function and problem except a float answer. Almost all of the problem (on your and mine level at least) can be solved without float numbers, and you won't get a lot of problems using them. Just an advice, ofc.