問題一覧 > 通常問題

No.3145 Astral Parentheses Sequence

レベル : / AI推定難易度 : 1525 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 58
作問者 : nauclhlt / テスター : 👑 p-adic naniwazu
お気に入りにしたユーザー ProblemId : 12058 / 自分の提出
問題文最終更新日: 2025-05-15 08:30:21
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 467 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。