CF1095E.Almost Regular Bracket Sequence
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets.
A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.
You can change the type of some bracket si. It means that if $s_i = $ ')' then you can change it to '(' and vice versa.
Your task is to calculate the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.
给你一个由 n 个左括号 '(' 和右括号 ')' 组成的括号序列 s。
合法括号序列(regular bracket sequence)是指:通过在原序列的字符之间插入字符 '1' 和 '+',可将其转化为一个正确的算术表达式。例如,括号序列 "()()" 和 "(())" 是合法的(对应表达式分别为 "(1)+(1)" 和 "((1+1)+1)"),而 ")(" 和 "(" 则不是。
你可以将某个位置 si 上的括号类型进行翻转:即若 $s_i = $ ')',则可将其改为 '(';反之亦然。
你的任务是:计算满足如下条件的位置 i 的个数——即若将第 i 个括号的类型翻转,则所得括号序列成为合法括号序列。
输入格式
The first line of the input contains one integer n (1≤n≤106) — the length of the bracket sequence.
The second line of the input contains the string s consisting of n opening '(' and closing ')' brackets.
输入的第一行包含一个整数 n(1≤n≤106)——括号序列的长度。
输入的第二行包含一个由 n 个左括号 '(' 和右括号 ')' 组成的字符串 s。
输出格式
Print one integer — the number of positions i such that if you change the type of the i-th bracket, then the resulting bracket sequence becomes regular.
输出一个整数——即满足如下条件的位置 i 的个数:若将第 i 个括号的类型进行翻转,则所得括号序列变为合法序列。
输入输出样例
输入#1
6 (((())
输出#1
3
输入#2
6 ()()()
输出#2
0
输入#3
1 )
输出#3
0
输入#4
8 )))(((((
输出#4
0
输入解题思路,AI测评打分。不知道怎么写?