QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 512 MB 満点: 100

#7766. Bookmark

統計

Given $n$ and $k$, let $p$ be a permutation of order $n$. You can partition $p$ into exactly $k$ non-empty contiguous segments (i.e., choose $k-1$ cut points $1 \le x_1 < x_2 < \cdots < x_{k-1} < n$ to form the segments $[1, x_1], (x_1, x_2], \dots, (x_{k-1}, n]$), and then sort the numbers within each segment in ascending order to obtain a new permutation $q$.

Define $f(p)$ as the lexicographically smallest permutation $q$ that can be obtained among all possible partition schemes.

Given a permutation $q$ of order $n$, find the number of permutations $p$ of order $n$ such that $f(p) = q$. Output the answer modulo $998244353$.

Input

The first line contains two integers $n$ and $k$.

The second line contains $n$ integers, representing the permutation $q$.

Output

Output a single integer representing the answer.

Examples

Input 1

2 1
1 2

Output 1

2

Input 2

3 3
3 1 2

Output 2

1

Input 3

6 3
1 2 3 6 5 4

Output 3

13

Constraints

For all data, $1 \le n \le 500, 1 \le k \le n$.

  • Subtask 1 (10%): $n \le 6$.
  • Subtask 2 (20%): $n \le 10$.
  • Subtask 3 (30%): $q = (1, 2, \dots, n)$.
  • Subtask 4 (40%): No special restrictions.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.