A10290 | Paper task
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alex was programming while Valentina (his toddler daughter) got there and started asking many questions about the round brackets (or parenthesis) in the code. He explained her a bit and when she got it he gave her a task in order to finish his code on time.
For the purpose of this problem we consider only strings consisting of opening and closing round brackets, that is characters '(' and ')'.
The sequence of brackets is called correct if:
1. it's empty;
2. it's a correct sequence of brackets, enclosed in a pair of opening and closing brackets;
3. it's a concatenation of two correct sequences of brackets.
For example, the sequences "()()" and "((()))(())" are correct, while ")(()", "(((((" and "())" are not.
Alex took a piece of paper, wrote a string $s$ consisting of brackets and asked Valentina to count the number of distinct non-empty substrings of $s$ that are correct sequences of brackets. In other words, her task is to count the number of non-empty correct sequences of brackets that occur in a string $s$ as a substring (don't mix up with subsequences).
When Valentina finished the task, Alex noticed he doesn't know the answer. Help him don't loose face in front of Valentina and solve the problem!
For the purpose of this problem we consider only strings consisting of opening and closing round brackets, that is characters '(' and ')'.
The sequence of brackets is called correct if:
1. it's empty;
2. it's a correct sequence of brackets, enclosed in a pair of opening and closing brackets;
3. it's a concatenation of two correct sequences of brackets.
For example, the sequences "()()" and "((()))(())" are correct, while ")(()", "(((((" and "())" are not.
Alex took a piece of paper, wrote a string $s$ consisting of brackets and asked Valentina to count the number of distinct non-empty substrings of $s$ that are correct sequences of brackets. In other words, her task is to count the number of non-empty correct sequences of brackets that occur in a string $s$ as a substring (don't mix up with subsequences).
When Valentina finished the task, Alex noticed he doesn't know the answer. Help him don't loose face in front of Valentina and solve the problem!
输入格式
The first line of the input contains an integer $n$ ( $1<=n<=500000$ ) — the length of the string $s$ .
The second line contains a string $s$ of length $n$ consisting of only '(' and ')'.
The second line contains a string $s$ of length $n$ consisting of only '(' and ')'.
输出格式
Print the number of distinct non-empty correct sequences that occur in $s$ as substring.
输入输出样例
输入 #1
10 ()()()()()
输出 #1
5
输入 #2
7 )(())()
输出 #2
3
In the first sample, there are $5$ distinct substrings we should count: "()", "()()", "()()()", "()()()()" and "()()()()()".
In the second sample, there are $3$ distinct substrings we should count: "()", "(())" and "(())()".
In the second sample, there are $3$ distinct substrings we should count: "()", "(())" and "(())()".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted