304814: CF917A. The Monster
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
The Monster
题意翻译
## Description 给你一个字符串只包含`(` `)` `?`三种字符,`?`你可以按需求转换成`(`或`)`。 定义一个区间为正确的括号序列,当且仅当对该区间进行如下操作之后,该序列为空: 1. 每次删除序列中一对相邻的左右括号`()` 2. 直到删到不能再删 ## Input 一个长度不超过5000的字符串 ## Output 能转换成正确的括号序列的子区间数量 感谢@xunzhen 提供的翻译题目描述
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF917A/4c119b489e29bab2fd3dc778221019b04c8209ba.png)Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: - Empty string is a correct bracket sequence. - if $ s $ is a correct bracket sequence, then $ (s) $ is also a correct bracket sequence. - if $ s $ and $ t $ are correct bracket sequences, then $ st $ (concatenation of $ s $ and $ t $ ) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string $ s $ consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers $ (l,r) $ such that $ 1<=l<=r<=|s| $ and the string $ s_{l}s_{l+1}...\ s_{r} $ is pretty, where $ s_{i} $ is $ i $ -th character of $ s $ . Joyce doesn't know anything about bracket sequences, so she asked for your help.输入输出格式
输入格式
The first and only line of input contains string $ s $ , consisting only of characters '(', ')' and '?' ( $ 2<=|s|<=5000 $ ).
输出格式
Print the answer to Will's puzzle in the first and only line of output.
输入输出样例
输入样例 #1
((?))
输出样例 #1
4
输入样例 #2
??()??
输出样例 #2
7