Editorial for Ami Nhảy Bước


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

ami sẽ nhảy tới một vài bước và nhảy lùi một vài bước. Giả sử ở lần nhảy \(n\), ami đến được ô \(i\)\(t\) là tổng số ô nhảy lùi, ta có công thức như sau:

\(\frac{n*(n+1)}{2} - 2*t = i\)

Từ đó, ta có:

\(t = \frac{\frac{n*(n+1)}{2} - ?i}{2}\).

Nhận xét rằng với \(n\) tăng thì \(t\) tăng, vậy ta có thể dùng duyệt nhị phân để tìm kiếm \(n\) nhỏ nhất thoả mãn điều kiện.

Độ phức tạp là \(O(log(i))\) mỗi query.



Comments

There are no comments at the moment.