A12616 | Bicolored RBS
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are RBS and ")(" and "(()" are not.
We can see that each opening bracket in RBS is paired with some closing bracket, and, using this fact, we can define nesting depth of the RBS as maximum number of bracket pairs, such that the $2$ -nd pair lies inside the $1$ -st one, the $3$ -rd one — inside the $2$ -nd one and so on. For example, nesting depth of "" is $0$ , "()()()" is $1$ and "()((())())" is $3$ .
Now, you are given RBS $s$ of even length $n$ . You should color each bracket of $s$ into one of two colors: red or blue. Bracket sequence $r$ , consisting only of red brackets, should be RBS, and bracket sequence, consisting only of blue brackets $b$ , should be RBS. Any of them can be empty. You are not allowed to reorder characters in $s$ , $r$ or $b$ . No brackets can be left uncolored.
Among all possible variants you should choose one that minimizes maximum of $r$ 's and $b$ 's nesting depth. If there are multiple solutions you can print any of them.
We can see that each opening bracket in RBS is paired with some closing bracket, and, using this fact, we can define nesting depth of the RBS as maximum number of bracket pairs, such that the $2$ -nd pair lies inside the $1$ -st one, the $3$ -rd one — inside the $2$ -nd one and so on. For example, nesting depth of "" is $0$ , "()()()" is $1$ and "()((())())" is $3$ .
Now, you are given RBS $s$ of even length $n$ . You should color each bracket of $s$ into one of two colors: red or blue. Bracket sequence $r$ , consisting only of red brackets, should be RBS, and bracket sequence, consisting only of blue brackets $b$ , should be RBS. Any of them can be empty. You are not allowed to reorder characters in $s$ , $r$ or $b$ . No brackets can be left uncolored.
Among all possible variants you should choose one that minimizes maximum of $r$ 's and $b$ 's nesting depth. If there are multiple solutions you can print any of them.
输入格式
The first line contains an even integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the length of RBS $s$ .
The second line contains regular bracket sequence $s$ ( $|s| = n$ , $s_i \in \{$ "(", ")" $\}$ ).
The second line contains regular bracket sequence $s$ ( $|s| = n$ , $s_i \in \{$ "(", ")" $\}$ ).
输出格式
Print single string $t$ of length $n$ consisting of "0"-s and "1"-s. If $t_i$ is equal to 0 then character $s_i$ belongs to RBS $r$ , otherwise $s_i$ belongs to $b$ .
输入输出样例
输入 #1
2 ()
输出 #1
11
输入 #2
4 (())
输出 #2
0101
输入 #3
10 ((()())())
输出 #3
0110001111
In the first example one of optimal solutions is $s = $ " $\color{blue}{()}$ ". $r$ is empty and $b = $ " $()$ ". The answer is $\max(0, 1) = 1$ .
In the second example it's optimal to make $s = $ " $\color{red}{(}\color{blue}{(}\color{red}{)}\color{blue}{)}$ ". $r = b = $ " $()$ " and the answer is $1$ .
In the third example we can make $s = $ " $\color{red}{(}\color{blue}{((}\color{red}{)()}\color{blue}{)())}$ ". $r = $ " $()()$ " and $b = $ " $(()())$ " and the answer is $2$ .
In the second example it's optimal to make $s = $ " $\color{red}{(}\color{blue}{(}\color{red}{)}\color{blue}{)}$ ". $r = b = $ " $()$ " and the answer is $1$ .
In the third example we can make $s = $ " $\color{red}{(}\color{blue}{((}\color{red}{)()}\color{blue}{)())}$ ". $r = $ " $()()$ " and $b = $ " $(()())$ " and the answer is $2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted