Hide and Seek 2
Time limit2sMemory limit512 MB
Find the minimum time for Subin to reach position K using steps of minus or plus 1 and doubling, plus the number of distinct shortest action sequences.
- Level
Medium7 of 10
- Topics
- BFS, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
Subin plays hide and seek with a younger sibling. Subin is at point and the sibling is at point . Subin either walks or teleports. When Subin is at position and walks, one second later Subin is at or . When Subin teleports, one second later Subin is at .
Subin never moves to a position below or above . The sibling stays in place.
Given both positions, write a program that finds the earliest time at which Subin reaches the sibling and the number of ways to reach the sibling in that time. Two ways are different when the sequence of actions differs. At position , for example, walking forward and teleporting both lead to position , and because the actions differ they count as two separate ways.
Input
The first line contains the position of Subin and the position of the sibling, separated by a space. Both values are integers with and .
Output
On the first line print the earliest time at which Subin finds the sibling.
On the second line print the number of ways to find the sibling in that time.