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

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

Problem Link: https://codeforces.me/edu/course/2/lesson/6/2/practice/contest/283932/problem/A

Accepted Code
Not Accepted Code

The only change in the two code is the value being assigned to l, when i normally implement binary search i use it like in the not accepted one but why in this problem its giving wrong answer?

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

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

Auto comment: topic has been updated by coder__12345 (previous revision, new revision, compare).

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

First code finds point where isfit changes 'sign', if isfit(l) before running BS was = false you don't need to check it anymore, answer is always r. Second code is kind of mix with no clear idea behind it. It should work after changing to while r>l, but 1st is just a lot better concept.

btw mid = (l+r)/2 saves some keystrokes.