問題一覧 > 通常問題

No.2106 Wild Cacco

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

Problem Statement

A string $t$ consisting only of (,),? is called a good string if it satisfies the following condition.

  • By appropriately replacing each ? in $t$ with either (,), $t$ can be made into a correct bracket sequence.

For example, $t=$ ?(?) is a good string, since it can be made into (()) by replacing the ? characters.
Similarly, $t=$ ???? and $t=$ ()()() are also good strings ($t$ does not necessarily have to contain ?).
On the other hand, $t=$ )??? is not a good string, since it does not become a correct bracket sequence no matter how the ? characters are replaced.

You are given a string $s$ consisting only of (,),?,..
How many good strings can be obtained by replacing each . in $s$ with one of (,),??
Since the answer can be very large, find it modulo $998244353$.

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 formed by concatenating ($,A,$ ) in this order is also a correct bracket sequence.
  3. If non-empty strings $A,B$ are correct bracket sequences, then the string formed 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.

Constraints

  • $s$ is a string consisting only of (,),?,..
  • $1\le |s|\le 4000$

Input

The input is given from standard input in the following format.

$s$

Output

Output the number of good strings that can be obtained by replacing each . in $s$ with one of (,),?, modulo $998244353$.

Sample

Sample 1
Input
..
Output
4

There are $4$ such strings: (), ?), (?, ??.

Sample 2
Input
((.?
Output
2

There are $2$ such strings: (()?, ((??.

Sample 3
Input
(())
Output
1

Sample 4
Input
((()
Output
0

Sample 5
Input
(...)?..?.
Output
358

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