問題一覧 > 通常問題

No.1684 Find Brackets

レベル : / AI推定難易度 : 2050 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 35
作問者 : Sumitacchan / テスター : 👑 hitonanode ygussany
お気に入りにしたユーザー ProblemId : 6809 / 自分の提出
問題文最終更新日: 2021-12-31 19:22:38
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 314 (順位表) の他の問題:

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).
  • $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$.
What is the minimum possible length of the string $T$?
For example, when $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.

  1. The empty string is a correct bracket sequence.
  2. 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.
  3. 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.
  4. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。