CodeTON Round 3 (Div. 1 + Div. 2, Rated, Prizes!)
F
Majority
Codeforces
2700
原题
← EG →
翻译中…

Everyone was happy coding, until suddenly a power shortage happened and the best competitive programming site went down. Fortunately, a system administrator bought some new equipment recently, including some UPSs. Thus there are some servers that are still online, but we need all of them to be working in order to keep the round rated.

翻译中…

Imagine the servers being a binary string $s$ of length $n$. If the $i$-th server is online, then $s_i = 1$, and $s_i = 0$ otherwise.

翻译中…

A system administrator can do the following operation called electricity spread, that consists of the following phases:

翻译中…
  • Select two servers at positions $1 \le i \lt j \le n$ such that both are online (i.e. $s_i=s_j=1$). The spread starts only from online servers.
  • Check if we have enough power to make the spread. We consider having enough power if the number of turned on servers in range $[i, j]$ is at least the number of turned off servers in range $[i, j]$. More formally, check whether $2 \cdot (s_i + s_{i+1} + \ldots + s_j) \ge j - i + 1$.
  • If the check is positive, turn on all the offline servers in range $[i, j]$. More formally, make $s_k := 1$ for all $k$ from $i$ to $j$.
翻译中…

We call a binary string $s$ of length $n$ rated if we can turn on all servers (i.e. make $s_i = 1$ for $1 \le i \le n$) using the electricity spread operation any number of times (possibly, $0$). Your task is to find the number of rated strings of length $n$ modulo $m$.

翻译中…

Input

翻译中…

The first and only line contains two integers $n$ and $m$ ($1 \le n \le 5000$, $10 \le m \le 10^9$) — the length of the string and the required module.

翻译中…

Output

翻译中…

Print a single integer — the number of rated binary strings of length $n$. Since this number can be large, print it modulo $m$.

翻译中…

Note

翻译中…

In the first example, the only rated string is 11. So the answer is $1$.

翻译中…

In the second example, the rated strings are:

翻译中…
  • 111;
  • 101, because we can perform an operation with $i = 1$ and $j = 3$.
翻译中…

So the answer is $2$.

翻译中…

In the third sample, the rated strings are:

翻译中…
  • 1001;
  • 1111;
  • 1011;
  • 1101.
翻译中…

So the answer is $4$.

翻译中…

样例

Input #1
2 100
Output #1
1
InputCopy OutputCopy
Input #2
3 10
Output #2
2
InputCopy OutputCopy
Input #3
4 3271890
Output #3
4
InputCopy OutputCopy
Input #4
17 123456
Output #4
32347
InputCopy OutputCopy
题目信息
题号
1750F
时间限制
2 s
内存限制
1024 MB
标签
组合数学
动态规划
数学
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。