1374C — Move Brackets

Правка en1, от MelitoMT, 2023-02-11 06:16:28

We are given two cases in which we can obtain regular bracket sequences (RBS) being "()()" , "(())", we can summarize this with an observation. As it is guaranteed that we can always arrange the brackets in a way we obtain a RBS, we only have to worry with the cases in which we have the closing bracket before the opening bracket, cases like ")(", note that if we count the occurrences of opening and closing brackets whenever we have one of this cases we will have that the count of closing brackets is bigger that the count of opening brackets. Let's use an example, given the input ")))((((())" we start counting, just before the first opening bracket, we will already have the closing brackets count in 3, that is, we will need 3 movements so far. Being said this, we will need a count of the difference of closing brackets and opening brackets, and whenever it gets to a maximum value we have a new number of least movements to obtain a RBS (the variable max in the code below).

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский MelitoMT 2023-02-11 06:16:28 1095 Initial revision (published)