Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

daihan's blog

By daihan, history, 7 years ago, In English

Hello codeforces community , i am trying to solve this problem :link . I am getting WA in test 15 , but i copied the test case on my compiler codeblocks , it gives correct output which judge want (expected output) . In judge compiler they saying my code gives output 2 , but i checked in my compiler which gives output 1 , which is correct . Dont know why this happening .

My code : https://pastebin.com/NE3sRLrR

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it +1 Vote: I do not like it

The problem with your code is that it is depending too much on the accuracy of log10() function and then typecasting it to the integer which is to the greatest integer function.

Suppose if a double nth(as in your code) = 3.999999999999 in my system and 4.00000000000 in your system, this will differ the whole answer. It is not a good option to depend too much on the accuracies of the system.

See this code, I just edited the 137th line in your code, type-casted from double to long double.

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

    Just asking, is it a good idea to use long double instead of double always to prevent precision loss? ( If there is no problem with memory limit ). I do not know if that will help.

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

      For similar reason we don't always use int64 instead of int32: Speed.

      Since long double uses more digits of precisions than double, it is slower than double (try multiplying two doubles and two long doubles and see the difference). I don't know any other disadvantage but I always use double and I've never got a WA due to precision if my algorithm is correct. For most of the time, using double is enough.