luogu#P5204. [USACO19JAN] Train Tracking 2 P
[USACO19JAN] Train Tracking 2 P
Background
USACO January 2019 Contest, Platinum Problem 3.
Problem Description
Every day, an express train passes by the farm. The train has cars (). Each car has a positive integer label between and ; different cars may have the same label.
Normally, Bessie watches the passing train and records the labels on the cars. But today the fog is so thick that Bessie cannot see a single label. Luckily, she learned from a reliable source in the city the minimum values of all sliding windows of the label sequence. Specifically, she is given a positive integer , and positive integers , where is the minimum label among cars .
Help Bessie find the number of ways to assign labels to all cars such that all the sliding-window minimum values match. Since this number may be very large, output it modulo .
Bessie's information is completely reliable; in other words, it is guaranteed that there exists at least one valid labeling.
Input Format
The first line contains two space-separated integers and . The remaining lines contain all sliding-window minimum values , one number per line.
Output Format
Output one integer: the number of ways to assign each car a positive integer label not exceeding , modulo , such that the minimum label among cars equals , for all .
4 2
999999998
999999999
999999998
3
Hint
Translated by ChatGPT 5