AT_arc230_c.Buildings
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer N that is at least 2, and N−1 integers C1,C2,…,CN−1.
There are N buildings lined up on a number line. The i-th building stands at position i and has height Hi. It is known that (H1,H2,…,HN) is a permutation of (1,2,…,N), but the specific values of H1,H2,…,HN are not known.
Find the number, modulo 998244353, of possible sequences (H1,H2,…,HN) such that the following condition holds for all of x=1,2,…,N−1.
- The number of buildings visible from position x+0.5 is Cx. Here, the i-th building is visible if and only if there is no building with height greater than Hi between position x+0.5 and position i.
给定一个不小于 2 的整数 N,以及 N−1 个整数 C1,C2,…,CN−1。
在一条数轴上并排矗立着 N 栋建筑。第 i 栋建筑位于位置 i,其高度为 Hi。已知 (H1,H2,…,HN) 是 (1,2,…,N) 的一个排列,但 H1,H2,…,HN 的具体取值未知。
求满足以下条件的序列 (H1,H2,…,HN) 的个数(对 998244353 取模):
- 对每个 x=1,2,…,N−1,从位置 x+0.5 处可见的建筑数量恰好为 Cx。
其中,第 i 栋建筑可见,当且仅当在位置 x+0.5 与位置 i 之间不存在高度严格大于 Hi 的建筑。
输入格式
The input is given from Standard Input in the following format:
N
C1 C2 … CN−1
输入从标准输入中按以下格式给出:
N
C1 C2 … CN−1
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
4 2 2 3
输出#1
3
输入#2
3 2 1
输出#2
0
输入#3
7 3 3 3 3 4 4
输出#3
85
说明/提示
Sample 1 Explanation:
For example, (H1,H2,H3,H4)=(3,4,2,1) satisfies the condition. Indeed,
-
For x=1, the buildings visible from position x+0.5=1.5 are the first and second buildings; there are 2=C1 such buildings.
-
For x=2, the buildings visible from position x+0.5=2.5 are the second and third buildings; there are 2=C2 such buildings.
-
For x=3, the buildings visible from position x+0.5=3.5 are the second, third, and fourth buildings; there are 3=C3 such buildings.
There are three sequences (H1,H2,H3,H4) satisfying the condition, including this one.
Sample 2 Explanation:
There may be no sequence (H1,H2,…,HN) satisfying the condition.
Constraints
- 2≤N≤2×105
- 1≤Cx≤N
- All input values are integers.
样例 1 解释:
例如,(H1,H2,H3,H4)=(3,4,2,1) 满足条件。事实上,
-
当 x=1 时,从位置 x+0.5=1.5 处可见的建筑物为第一栋和第二栋;这样的建筑物共有 2=C1 栋。
-
当 x=2 时,从位置 x+0.5=2.5 处可见的建筑物为第二栋和第三栋;这样的建筑物共有 2=C2 栋。
-
当 x=3 时,从位置 x+0.5=3.5 处可见的建筑物为第二栋、第三栋和第四栋;这样的建筑物共有 3=C3 栋。
满足条件的序列 (H1,H2,H3,H4) 共有三个,本例即为其中之一。
样例 2 解释:
可能不存在满足条件的序列 (H1,H2,…,HN)。
约束条件
- 2≤N≤2×105
- 1≤Cx≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?