cooldudeperfect's blog

By cooldudeperfect, history, 3 years ago, In English

200417545 This is the submission that I made during the contest which got accepted on pretests but gave wrong answer on main test 15.

200514283 I made this submission after the contest and the only change I did was to change lower_bound to upper_bound and it got accepted.

If someone can figure out what is going wrong with lower_bound that would be awesome.

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

| Write comment?
»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

lower_bound() is used to return an iterator pointing to the first element in the range which has a value >= val. But the bound we're setting on K is (b — 2*sqrt(a*c) , b + 2*sqrt(a*c)). which is non inclusive of the extremities. lower bound may find the value of K which is equal to the left extremity in your case. But upper_bound() on the other hand returns an iterator pointing to the first element in the range which has a value strictly greater than val. the forementioned case is taken care of here and hence the solutions gets ac on upper_bound() and not on lower_bound()

»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my approach using lower_bound that got accepted submission

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

I think the issue with your solution is sqrt and doubles being imprecise rather than lower bound

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

You have to check both values, like suppose lower_bound gave you the value less than iterator to n-1 then check once at that point and also check at one point before that point. This does confirm your result cuz (b-k[i])^2 is positive either you go a bit far from b or you keep k[i] less than b.

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

When you use double, you give your fate to the god.

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

Why would you expect both submissions to receive the same verdict when upper_bound does a different thing from lower_bound?

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

I was solving a problem, max gave the wrong answer while min gave the correct answer.

Sounds ridiculous? That's the same thing.

upper_bound and lower_bound are different functions. That they give different results isn't surprising.