問題一覧 > 通常問題

No.3099 Parentheses Decomposition

レベル : / AI推定難易度 : 1400 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 97
作問者 : shobonvip / テスター : noya2
お気に入りにしたユーザー ProblemId : 11623 / 自分の提出
問題文最終更新日: 2025-04-11 21:19:22
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 464 (順位表) の他の問題:

Problem Statement

A correct parenthesis sequence is defined as a string satisfying one of the following conditions.

  • It is the empty string.
  • There exists a correct parenthesis sequence $A$ such that the string is the concatenation of (, $A$, ) in this order.
  • There exist non-empty correct parenthesis sequences $A, B$ such that the string is the concatenation of $A, B$ in this order.

For example, (())() is a correct parenthesis sequence, while ()( and )( are not.

For a positive even number $N$, a type A correct parenthesis sequence of length $N$ is defined as follows.

  • For $1 \le i \le N/2$, $S_i$ is (.
  • For $N/2+1 \le i \le N$, $S_i$ is ).

For example, (()) and ((((())))) are type A correct parenthesis sequences.

For a positive even number $N$, a type B correct parenthesis sequence of length $N$ is defined as follows.

  • If $i$ is odd, $S_i$ is (.
  • If $i$ is even, $S_i$ is ).

For example, ()() and ()()()()() are type B correct parenthesis sequences.

You are given a correct parenthesis sequence $S$ of length $N$ that is type A or type B. Find the number of sequences $T$ of length $N$ consisting of $0, 1$ that satisfy the following conditions.

  • If there exists an integer $i$ $(1\le i \le N)$ with $T_i = 0$, let $P_1, \cdots, P_k$ be the indices $i$ with $T_i = 0$ in ascending order. Let $X$ be the concatenation of $S_{P_1}, \cdots, S_{P_k}$ in this order; then $X$ is a correct parenthesis sequence.
  • If there exists an integer $i$ $(1\le i \le N)$ with $T_i = 1$, let $Q_1, \cdots, Q_l$ be the indices $i$ with $T_i = 1$ in ascending order. Let $Y$ be the concatenation of $S_{Q_1}, \cdots, S_{Q_l}$ in this order; then $Y$ is a correct parenthesis sequence.

Since the answer can be very large, output it modulo $998244353$.

Constraints

  • $2 \le N \le 5\times 10^5$
  • $N$ is even.
  • $S$ is a type A or type B correct parenthesis sequence.

Input

$N$
$S$

Output

Output the answer.

Sample

Sample 1
Input
4
(())
Output
6

The input string is a type A correct parenthesis sequence. The sequences $T$ satisfying the conditions and the corresponding $X$, $Y$ are as follows.

$T$$X$$Y$
0000(())None
0101()()
0110()()
1001()()
1010()()
1111None(())
There are $6$ of them in total, so output $6$.
Sample 2
Input
4
()()
Output
4

The input string is a type B correct parenthesis sequence.

Sample 3
Input
2
()
Output
2

The input string is a correct parenthesis sequence of both type A and type B.

Sample 4
Input
40
(((((((((((((((((((())))))))))))))))))))
Output
88808106

Output the answer modulo $998244353$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。