No.3145 Astral Parentheses Sequence
Story
nauclhlt came up with a romantic parentheses sequence!
Problem Statement
A string $X$ is called an astral parentheses sequence if it satisfies the following.
- $X$ can be turned into the empty string by repeating, $0$ or more times, the operation of deleting a
(*)contained in $X$ as a substring
Given a positive integer $N$, find the number of possible astral parentheses sequences of length $N$.
Since the answer can be very large, find the remainder when it is divided by $M$ (a positive integer given in the input).
Input
$N\ M$
- $1\leq N\leq 1500$
- $2\leq M\leq 10^9$
- $N, M$ are integers
Output
Let $r$ be the remainder when the number of possible astral parentheses sequences of length $N$ is divided by $M$. Output it on one line in the following format.
$r$
Print a newline at the end.
Sample
Sample 1
Input
6 2
Output
1
There are $3$ astral parentheses sequences of length $6$: (*)(*), (*(*)), and ((*)*). Therefore, the answer is 1, the remainder when $3$ is divided by $2$.
Note here that $M$ is not necessarily prime.
Sample 2
Input
4 998244353
Output
0
There is no astral parentheses sequence of length $4$.
Sample 3
Input
1500 998244353
Output
201238254
In this example, output the remainder when divided by $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nauclhlt
naniwazu