No.1684 Find Brackets
タグ : / 解いたユーザー数 35
作問者 :
Sumitacchan
/ テスター :
👑
hitonanode
Problem Statement
For a string $S$ of length $N$ consisting only of ( and ), consider the following problem, and let $f(S)$ be its answer.
A string $T$ satisfies both of the following $2$ conditions (it can be proved that such a $T$ always exists).For example, when $S={}$
What is the minimum possible length of the string $T$?
- $T$ consists only of
(and), and is a correct bracket sequence (see the notes below for the definition of a correct bracket sequence).- $S$ is a substring of $T$. That is, some contiguous subsequence of $T$ is equal to $S$.
)(, the shortest $T$ satisfying the conditions is $T={}$()(), so $f(S)=4$.Also, when $S={}$
(), we can take $T={}$(), so $f(S)=2$.
Consider the strings $S$ that contain at least $M$ occurrences of ( (there are $\sum_{i=M}^N\binom{N}{i}$ such strings $S$).
Find the sum of $f(S)$ over all such $S$.
Since the answer can be very large, output it modulo $10^9+7$.
Notes: A correct bracket sequence is defined as follows.
- The empty string is a correct bracket sequence.
- If a string $A$ is a correct bracket sequence, then the string obtained by concatenating
($,A,$)in this order is also a correct bracket sequence. - If strings $A,B$ are correct bracket sequences, then the string obtained by concatenating $A,B$ in this order is also a correct bracket sequence.
- Only strings satisfying one of the conditions 1 to 3 above are correct bracket sequences.
Input
$N\ \ M$
- $1\le N\le 10^6$
- $0\le M\le N$
- All inputs are integers.
Output
Output the sum of $f(S)$ modulo $10^9+7$.
Sample
Sample 1
Input
2 2
Output
4
We only need to consider $S={}$((. We can take $T={}$(()), so $f(S)=4$.
Sample 2
Input
2 1
Output
10
In addition to the case in Sample 1, we consider the cases $S={}$()$,$ )(.
Sample 3
Input
998244 353
Output
293243454
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。