luogu#P9018. [USACO23JAN] Moo Route G
[USACO23JAN] Moo Route G
题目描述
Farmer Nhoj dropped Bessie in the middle of nowhere! At time , Bessie is located at on an infinite number line. She frantically searches for an exit by moving left or right by unit each second. However, there actually is no exit and after seconds, Bessie is back at , tired and resigned.
Farmer Nhoj tries to track Bessie but only knows how many times Bessie crosses , given by an array $A_0,A_1, \cdots ,A_{N−1} (1 \le N \le 10^5, 1 \le A_i \le 10^6)$. Bessie never reaches nor .
In particular, Bessie's route can be represented by a string of Ls and Rs where the ith character represents the direction Bessie moves in during the ith second. The number of direction changes is defined as the number of occurrences of s plus the number of occurrences of s.
Please help Farmer Nhoj count the number of routes Bessie could have taken that are consistent with and minimize the number of direction changes. It is guaranteed that there is at least one valid route.
输入格式
The first line contains . The second line contains .
输出格式
The number of routes Bessie could have taken, modulo .
题目大意
【题目描述】
现在有一条数轴, 表示当前时刻。在 时 Bessie 恰好处在 的位置。
接下来,每秒钟 Bessie 会向左或者向右移动一个单位距离,我们保证 Bessie 是在 的位置之间移动并最终停在 的位置。同时,我们有一个 的数列,分别表示 Bessie 经过 这些点的次数。我们可以用一个由 和 组成的序列来表示 Bessie 的路径,我们称 Bessie 改变了一次方向为在序列中的相邻两个字符不同。现在我们不知道具体的移动序列是什么,但我们知道 Bessie 采用了让她改变方向次数最少的走法。现在请问 Bessie 的路径有多少种不同的可能情况?(我们称两条路径不同当且仅当这条路径对应序列中的某一位不同)
【输入格式】
第一行一个正整数表示 。
接下来一行有 个用空格分隔的正整数表示 。
【输出格式】
一行一个整数表示结果总数。由于这个值可能很大,请输出其对 取模的结果。
【数据范围】
。
对于测试点 ,满足 。
对于测试点 ,满足 。
对于测试点 ,满足 。
2
4 6
2
提示
Explanation for Sample 1
Bessie must change direction at least 5 times. There are two routes corresponding to Bessie changing direction exactly 5 times:
Scoring
- Inputs : and
- Inputs :
- Inputs :
- Inputs : No additional constraints.