Safe Racing
Time limit2sMemory limit512 MB
Count binary circular arrangements of L booths where every S consecutive booths contain at least one marshal, modulo 123456789.
- Level
Medium6 of 10
- Topics
- Combinatorics, Dynamic programming, Sliding window
- Solved
- No attempts yet
Problem
Tomorrow is race day. Track marshals stand along the circuit with flags they use to signal the drivers: a yellow flag warns of danger, and a blue flag orders a lapped car to let a faster car through. Each marshal works from a marshal booth, a protected cage that is clearly visible from the track.
The track is circular and decametres long. A booth sits every ten metres (one decametre), so there are exactly booths, at distances decametres from the start.
Not every booth has to be used. The regulations cap the distance between two consecutive marshals at decametres, which means that any booths that are consecutive around the circle must contain at least one marshal. Marshals do not wave the finish flag, so a marshal at the start/finish booth is neither required nor forbidden.
Count the marshal assignments that satisfy the regulation and report the count modulo .
Input
The input contains two integers and , the length of the track and the maximal distance between consecutive marshals ().
Output
Print on one line the number of valid assignments modulo . The printed value satisfies .
Hint
For and there are four valid assignments: marshals at 0 and 1 decametres from the start, at 0 and 2, at 1 and 2, or at 0, 1 and 2.