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

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

Hello, since gym doesn't allow to see others solutions could someone help with this problem:

i have tried this solution but got WA

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

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

You actually don't need DP to solve this problem.

Think of it like this, Bus Stops means that you have segments in the form $$$(li, ri)$$$. In these segments you don't need to walk.

This means that if consecutive segments (let's say $$$(li, ri)$$$ & $$$(lj, rj)$$$ assuming $$$ri \lt =lj$$$ and $$$rj \gt =ri$$$) are intersecting you don't need to walk in the segment $$$(li, rj)$$$ at all.

So now this problem becomes for the distance (1, n) how many places have no segments. That is the answer. For merging segments you can sort and merge, I think it's pretty well known.

code