AtCoder Grand Contest 054
翻译中…
Problem Statement
翻译中…
Snuke received a permutation $P=(P_1,P_2,\cdots,P_N)$ of $(1,\ 2,\ ...\ N)$ and an integer $K$. He did some number of swaps of two adjacent elements in $P$ so that the following condition would be satisfied.
翻译中…
- For each
$1 \leq i \leq N$, there are at most$K$indices$j$such that$1 \leq j< i$and$P_j>P_i$.
翻译中…
Here, he did the minimum number of swaps needed to achieve this condition.
翻译中…
Afterward, he has forgotten the original permutation he received. Given the permutation $P'$ after the swaps, find the number, modulo $998244353$, of permutations that the original permutation $P$ could be.
翻译中…
Constraints
翻译中…
$2 \leq N \leq 5000$$1 \leq K \leq N-1$$1 \leq P'_i \leq N$$P'_i \neq P'_j$($i \neq j$)- For each
$1 \leq i \leq N$, there is at most$K$indices$j$such that$1 \leq j< i$and$P'_j>P'_i$. - All values in input are integers.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
N K
P'_1 P'_2 \cdots P'_N
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
3 1
3 1 2
Output #1
2
$P$ could be one of the following two permutations.
- $P=(3,1,2)$: The minimum number of swaps needed is $0$. After zero swaps, the permutation is equal to $P'$.
- $P=(3,2,1)$: The minimum number of swaps needed is $1$: swapping $P_2$ and $P_3$ results in $P=(3,1,2)$, which satisfies the condition and is equal to $P'$.
Input #2
4 3
4 3 2 1
Output #2
1
Input #3
5 2
4 2 1 5 3
Output #3
3
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。