AT_abc457_f.Second Gap
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer N and an integer sequence D=(D1,D2,…,DN−1) of length N−1.
Find the number, modulo 998244353, of permutations P=(P1,P2,…,PN) of (1,2,…,N) that satisfy the following condition.
- For each 1≤i≤N−1, let Pa and Pb be the elements with the largest and the second largest values, respectively, among (Pi,Pi+1,…,PN); then ∣a−b∣=Di.
给定一个整数 N 和一个长度为 N−1 的整数序列 D=(D1,D2,…,DN−1)。
求满足以下条件的排列 P=(P1,P2,…,PN)(即 (1,2,…,N) 的一个排列)的个数,答案对 998244353 取模。
- 对每个 1≤i≤N−1,设 Pa 和 Pb 分别为子序列 (Pi,Pi+1,…,PN) 中最大值和次大值所对应的元素;则需满足 ∣a−b∣=Di。
输入格式
The input is given from Standard Input in the following format:
N
D1 D2 … DN−1
输入从标准输入中按以下格式给出:
N
D1 D2 … DN−1
输出格式
Output the number, modulo 998244353, of permutations satisfying the condition.
输出满足该条件的排列数量,对 998244353 取模。
输入输出样例
输入#1
3 1 1
输出#1
4
输入#2
5 1 2 2 1
输出#2
0
输入#3
15 4 4 4 4 4 4 3 2 2 2 2 2 1 1
输出#3
70270200
说明/提示
Sample 1 Explanation:
For example, we can verify that (2,3,1) satisfies the condition as follows.
-
We have (P1,P2,P3)=(2,3,1). The largest value is P2 and the second largest value is P1, and ∣2−1∣=1=D1.
-
We have (P2,P3)=(3,1). The largest value is P2 and the second largest value is P3, and ∣2−3∣=1=D2.
Four permutations satisfy the condition: (1,2,3),(1,3,2),(2,3,1),(3,2,1). Thus, output 4.
Constraints
- 2≤N≤2×105
- 1≤Di≤N−i
- All input values are integers.
样例 1 解释:
例如,我们可以验证排列 (2,3,1) 满足条件,如下所示。
- 此时 (P1,P2,P3)=(2,3,1)。其中最大值为 P2,次大值为 P1,且 ∣2−1∣=1=D1。
- 此时 (P2,P3)=(3,1)。其中最大值为 P2,次大值为 P3,且 ∣2−3∣=1=D2。
共有四个排列满足条件:(1,2,3), (1,3,2), (2,3,1), (3,2,1)。因此输出 4。
约束条件
- 2≤N≤2×105
- 1≤Di≤N−i
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?