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

Автор cooldudeperfect, история, 3 года назад, По-английски

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.

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

my approach using lower_bound that got accepted submission

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

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

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

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 года назад, скрыть # |
 
Проголосовать: нравится +28 Проголосовать: не нравится

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

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

»
3 года назад, скрыть # |
 
Проголосовать: нравится +13 Проголосовать: не нравится

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.