No.1885 Flat Permutation
タグ : / 解いたユーザー数 126
作問者 :
miscalc
/ テスター :
Problem Statement
You are given integers $N, X, Y$. Find the number of permutations $P = (P_1, P_2, \ldots, P_N)$ of $(1, 2, \ldots, N)$ that satisfy all of the following conditions.
- $P_1 = X$
- $P_N = Y$
- $|P_{i+1} - P_i| \leq 2$ ($1 \leq i \leq N - 1$)
Input
$N$ $X$ $Y$
- All input values are integers.
- $2 \leq N \leq 2 \times 10^5$
- $1 \leq X, Y \leq N$
- $X \neq Y$
Output
Output the number of $P$ satisfying the conditions, modulo $998244353$. End the output with a newline.
Sample
Sample 1
Input
4 1 4
Output
2
The $2$ permutations $P = (1, 2, 3, 4), (1, 3, 2, 4)$ satisfy the conditions.
Sample 2
Input
6 3 5
Output
1
Only $P = (3, 1, 2, 4, 6, 5)$ satisfies the conditions.
Sample 3
Input
4 3 2
Output
0
No $P$ satisfies the conditions.
Sample 4
Input
31415 9265 3589
Output
889048175
Output the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。