Makaty's blog

By Makaty, history, 2 years ago, In English

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

i have tried this solution but got WA

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

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