

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 550 点
問題文
正整数 N,M および、各要素が 1 以上 N 以下の整数である長さ N の数列 A=(A_1,A_2,\dots,A_N) が与えられます。
各要素が 1 以上 M 以下の整数である長さ N の数列 x=(x_1,x_2,\dots,x_N) のうち、以下の条件を満たすものの数を 998244353 で割った余りを求めてください。
- 全ての i\ (1\leq i\leq N) について、x_i \leq x_{A_i}
制約
- 1\leq N,M \leq 2025
- 1\leq A_i\leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N
出力
答えを出力せよ。
入力例 1
3 3 2 1 1
出力例 1
6
x=(1,1,1),(2,2,1),(2,2,2),(3,3,1),(3,3,2),(3,3,3) が条件を満たします。
入力例 2
4 9 1 1 1 1
出力例 2
2025
入力例 3
10 5 9 4 5 5 4 2 1 5 7 2
出力例 3
10010
Score : 550 points
Problem Statement
You are given positive integers N, M, and a sequence A = (A_1, A_2, \dots, A_N) of length N, each element being an integer between 1 and N, inclusive.
Find the number, modulo 998244353, of sequences x = (x_1, x_2, \dots, x_N) of length N, each element being an integer between 1 and M, inclusive, that satisfy the following condition:
- x_i \leq x_{A_i} for every i (1 \leq i \leq N).
Constraints
- 1 \leq N, M \leq 2025
- 1 \leq A_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N
Output
Print the answer.
Sample Input 1
3 3 2 1 1
Sample Output 1
6
The sequences x=(1,1,1),(2,2,1),(2,2,2),(3,3,1),(3,3,2),(3,3,3) satisfy the condition.
Sample Input 2
4 9 1 1 1 1
Sample Output 2
2025
Sample Input 3
10 5 9 4 5 5 4 2 1 5 7 2
Sample Output 3
10010