AtCoder Grand Contest 071
B
Maximum Bracket Subsequence
AtCoder
⌀ 2842
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given integers $N$, $K$, and a correct bracket sequence $S$ of length $K$ consisting of ( and ).

翻译中…

Find the number, modulo $998244353$, of length-$N$ strings $T$ consisting of ( and ) that satisfy all of the following conditions:

翻译中…
  • There exists a (not necessarily contiguous) subsequence of $T$ that is a correct bracket sequence of length $K$.
  • Among all (not necessarily contiguous) subsequences of $T$ that are correct bracket sequences of length $K$, the lexicographically largest one is $S$.
翻译中…

Here, concerning the lexicographical order of strings consisting of ( and ), we consider ( smaller than ).

翻译中…

Notes on correct bracket sequences A correct bracket sequence is a string that can be transformed into the empty string by repeatedly deleting a substring that is () zero or more times.

翻译中…

Notes on lexicographical order A string $S = S_1S_2\ldots S_{|S|}$ is said to be lexicographically smaller than a string $T = T_1T_2\ldots T_{|T|}$ if either of the following holds. $|S| < |T|$ and $S_1S_2\ldots S_{|S|} = T_1T_2\ldots T_{|S|}$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that: $S_1S_2\ldots S_{i-1} = T_1T_2\ldots T_{i-1}$, $S_i$ is a character smaller than $T_i$.

翻译中…

Constraints

翻译中…
  • $K \leq N \leq 10^7$
  • $2 \leq K \leq 5 \times 10^5$
  • $N$ and $K$ are integers.
  • $S$ is a correct bracket sequence of length $K$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N K
S

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
7 4
(())
Output #1
20
For example, if $T=$`((())))`, the only (not necessarily contiguous) subsequence of $T$ that is a correct bracket sequence of length $4$ is `(())`, which equals $S$, so it satisfies the conditions. If $T=$`((())()`, there are two (not necessarily contiguous) subsequences of $T$ that are correct bracket sequences of length $4$: `()()` and `(())`. The lexicographically largest one is `()()`, so it does not satisfy the conditions.
Input #2
20 4
()()
Output #2
1047225
Input #3
71 10
()(()())()
Output #3
190654464
Input #4
10000000 28
(()()(()))(()((()))())()(())
Output #4
769035381
题目信息
题号
agc071_b
时间限制
2 s
内存限制
1024 MB

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