Logo
(追記) (追記ここまで)

19471번 - Parentheses 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB25151055.556%

문제

A correct parentheses sequence can be defined recursively as follows:

  • The empty string is a correct sequence.
  • If $X$ and $Y$ are correct sequences, then $X Y$ (the concatenation of $X$ and $Y$) is a correct sequence.
  • If $X$ is a correct sequence, then $(X)$ is a correct sequence.

Each correct parentheses sequence can be derived using the above rules.

For a parentheses sequence, you can make some operations with it.

  • Each time you can choose two indices $L$ and $R$ such that $L \le R$. The operation modifies the characters on indices from $L$ to $R,ドル inclusive.
  • First, the order of these characters is reversed.
  • Then, each character is toggled to the opposite one. That is, each '(' in the specified range changes to a ')' and vice versa.

The value of a parentheses sequence is the minimal number of the operations required to change it into a correct parentheses sequence. If it is impossible, the value of the sequence is equal to 10ドル^{100}$.

For example, the value of "()((" is 1ドル,ドル the value of "()()" is 0ドル,ドル and the value of "(((" is 10ドル^{100}$.

You are given an integer $n$. For each 1ドル \le i \le n,ドル find the number $A_i$ of different parentheses sequence of length $n$ which has value $i,ドル and then calculate the sum $\sum_{i = 0}^{n} ((i + 1) \cdot A_i)$.

The answer may be very large, so print it modulo the given integer $m$.

입력

The first line of the input contains two integers $n$ and $m$ (1ドル \le n \le 10^6,ドル 1ドル \le m \le 10^9$).

출력

Print one integer: the answer to the problem.

제한

예제 입력 1

1 100

예제 출력 1

0

예제 입력 2

10 100

예제 출력 2

68

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2016 > Day 4: Ce Bin and Ryyi Ji Contest 1 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /