AtCoder Regular Contest 194 (Div. 2)
翻译中…
Problem Statement
翻译中…
A string is defined to be a valid parenthesis sequence if and only if it satisfies one of the following conditions:
翻译中…
- It is an empty string.
- There exists a valid parenthesis sequence
$A$such that the string is obtained by concatenating(,$A$, and)in this order. - There exist non-empty valid parenthesis sequences
$A$and$B$such that the string is obtained by concatenating$A$and$B$in this order.
翻译中…
You are given a valid parenthesis sequence $S$ of length $N$. You can perform the following operation any number of times:
翻译中…
- Choose a contiguous substring of
$S$that is a valid parenthesis sequence, and reverse it.
翻译中…
Here, reversing the substring of $S$ from the $l$-th character to the $r$-th character means the following:
翻译中…
- For every integer
$i$satisfying$l \leq i \leq r$, simultaneously replace$S_i$with)if$S_{l+r-i}$is(, and with(if$S_{l+r-i}$is).(Note that reversing here is different from the usual definition of reversing.)
翻译中…
Find the number, modulo $998244353$, of distinct strings $S$ that you can have at the end of the process.
翻译中…
Constraints
翻译中…
$1 \leq N \leq 5000$$|S| = N$$S$is a valid parenthesis sequence.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
N
S
翻译中…
Output
翻译中…
Print the answer.
翻译中…
样例
Input #1
6
(())()
Output #1
2
For example, you can transform $S$ into `()(())` by doing the following:
- Choose the substring from the 1st to the 6th character of $S$. This is a valid parenthesis sequence. $S$ becomes `()(())`.
The only other string that can be formed is `(())()`. Thus, the answer is $2$.
Input #2
2
()
Output #2
1
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。