306872: CF1264D1. Beautiful Bracket Sequence (easy version)
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Beautiful Bracket Sequence (easy version)
题意翻译
给定一个含 `?` 的括号序列。定义一个括号序列的权值为删除一些字符使其成为合法的字符序列后,括号匹配的最深深度。求把 `?` 替换成括号的所有方案中,括号序列的权值之和。 $n\le 2000$题目描述
This is the easy version of this problem. The only difference is the limit of $ n $ - the length of the input string. In this version, $ 1 \leq n \leq 2000 $ . The hard version of this challenge is not offered in the round for the second division. Let's define a correct bracket sequence and its depth as follow: - An empty string is a correct bracket sequence with depth $ 0 $ . - If "s" is a correct bracket sequence with depth $ d $ then "(s)" is a correct bracket sequence with depth $ d + 1 $ . - If "s" and "t" are both correct bracket sequences then their concatenation "st" is a correct bracket sequence with depth equal to the maximum depth of $ s $ and $ t $ . For a (not necessarily correct) bracket sequence $ s $ , we define its depth as the maximum depth of any correct bracket sequence induced by removing some characters from $ s $ (possibly zero). For example: the bracket sequence $ s = $ "())(())" has depth $ 2 $ , because by removing the third character we obtain a correct bracket sequence "()(())" with depth $ 2 $ . Given a string $ a $ consists of only characters '(', ')' and '?'. Consider all (not necessarily correct) bracket sequences obtained by replacing all characters '?' in $ a $ by either '(' or ')'. Calculate the sum of all the depths of all these bracket sequences. As this number can be large, find it modulo $ 998244353 $ . Hacks in this problem in the first division can be done only if easy and hard versions of this problem was solved.输入输出格式
输入格式
The only line contains a non-empty string consist of only '(', ')' and '?'. The length of the string is at most $ 2000 $ .
输出格式
Print the answer modulo $ 998244353 $ in a single line.
输入输出样例
输入样例 #1
??
输出样例 #1
1
输入样例 #2
(?(?))
输出样例 #2
9