atcoder#AGC054D. [AGC054D] (ox)
[AGC054D] (ox)
Score : points
Problem Statement
Given is a string consisting of (
, )
, o
, and x
.
You can swap two adjacent characters in any number of times.
Find the minimum number of swaps needed to satisfy the following condition.
- Let us make a string consisting of
(
and)
by replacing every occurrence ofo
with()
and every occurrence ofx
with)(
in . Then, is a balanced parenthesis string.
Definition of a balanced parenthesis string
A balanced parenthesis string is a string that is one of the following:
- an empty string;
- a string that is a concatenation of , in this order, where and are some non-empty balanced parenthesis strings;
- a string that is a concatenation of
(
, ,)
in this order, where is some balanced parenthesis string.
Constraints
- is a string consisting of
(
,)
,o
, andx
. - contains the same non-zero number of
(
s and)
s.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
)x(
3
We should do as follows: )x(
→ x)(
→ x()
→ (x)
.
Here, we have ()()
, which is a balanced parenthesis string.
()ox
2
()oxo(xxx))))oox((oooxxoxo)oxo)ooo(xxx(oox(x)(x()x
68