No.2045 Two Reflections
タグ : / 解いたユーザー数 61
作問者 : 👑
hitonanode
Problem Statement
You are given $3$ positive integers $N,p,q$. A sequence $A$ of length $N$ initially satisfies $A_i=i \ (1\le i\le N)$.
Consider the following $2$ types of operations.
- Operation $1$: Reverse the first $p$ terms. That is, replace $A_1,A_2,\ldots,A_p$ with $A_p,A_{p-1},\ldots,A_1$.
- Operation $2$: Reverse the last $q$ terms. That is, replace $A_{N-q+1},\ldots,A_{N-1},A_N$ with $A_N,A_{N-1},\ldots,A_{N-q+1}$.
How many different sequences can be obtained by performing the operations $0$ or more times in any order? Find the answer modulo $998244353$.
Constraints
- $1\le N\le 10^5$
- $1\le p, q\le N$
- All input values are integers.
Input
$N$ $p$ $q$
Output
Find the number of sequences that can be obtained, and print it modulo $998244353$.
Sample
Sample 1
Input
4 2 2
Output
4
Operation $1$ replaces $A_1,A_2,A_3,A_4$ with $A_2,A_1,A_3,A_4$, and operation $2$ replaces $A_1,A_2,A_3,A_4$ with $A_1,A_2,A_4,A_3$. The sequences that can be obtained are the following:
- $1,2,3,4$
- $1,2,4,3$
- $2,1,3,4$
- $2,1,4,3$
for a total of $4$ sequences.
Sample 2
Input
10 4 7
Output
12
Sample 3
Input
100000 99999 99998
Output
451444810
Print the answer modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。