Educational Codeforces Round 65 (Rated for Div. 2) D - Bicolored RBS

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.

Input

The first line contains an even integer n

(2≤n≤2⋅105) — the length of RBS s

.

The second line contains regular bracket sequence s

(|s|=n, si∈{"(", ")"}

).

Output

Print single string t

of length n consisting of "0"-s and "1"-s. If ti is equal to 0 then character si belongs to RBS r, otherwise si belongs to b

.

Examples

Input

Copy

2
()

Output

Copy

11

Input

Copy

4
(())

Output

Copy

0101

Input

Copy

10
((()())())

Output

Copy

0110001111

Note

In the first example one of optimal solutions is s=

"()". r is empty and b= "()". The answer is max(0,1)=1

.

In the second example it's optimal to make s=

"(())". r=b= "()" and the answer is 1

.

In the third example we can make s=

"((()())())". r= "()()" and b= "(()())" and the answer is 2

.


直接模拟,所有左括号按10101010。。。排列,右括号与左边离自己最近且未匹配的左括号匹配

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#define ll long long
#define mod 998244353
using namespace std;
char a[205000];
int b[200500];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",a+1);
        int m=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]=='(')
            {
                m=(m+1)%2;
                b[i]=m;
            }
            else
            {
                b[i]=m;
                m=(m+1)%2;
            }
        }
        for(int i=1;i<=n;i++)
        {
            printf("%d",b[i]);
        }
        printf("\n");
    }
}

 

全部评论

相关推荐

会员标识
02-20 16:28
已编辑
牛客运营
从03年的“北大毕业生卖猪肉”到前段时间上热搜的“北大博士入职城管”,这些年“下沉式就业”现象频繁牵动着大家的视野和目光吧,很吸睛?我觉得并不是,如果你说985大学生XXX,那可能成不了焦点,如果说是北大清华毕业生去当城管,卖猪肉,大家都会讨论一番,无论是谁都知道北大清华的过人之处。但是呢近些年的确有很多985、211名校毕业生选择到基层就业或回老家创业,会不会觉得大财小用?老家的哥哥,因为当时学的专业不是很好,但好在学校不错,一路本硕连读,毕业之后在上海打拼了2年,也攒了一些小钱,随后回村选择科学养鸡,买了很大一块地开始科学方法的养鸡、卖鸡蛋,村里的老人都会议论纷纷,白瞎了家里供你读书,又回...
下午吃泡馍:不是每一个脱下长衫的人在下沉市场重获新生,并不是每一个养猪养鸡的高学历人才都会成功。现实是很多人的“长衫”就是自己为数不多甚至唯一的底牌了,拼尽全力拿到一个不错的学历,这时候主流媒体告诉对方脱下长衫也可以活的精彩,其实真的挺难过的。强者恒强,但是弱者是人群的底色。 本质上是整个市场的问题,没有足够多的增长点,没有足够多的岗位,自上而下没有积极向上的氛围。外企撤出,供应链缺失...在发展的过程中总有阵痛,现阶段可能就是我们承受阵痛的过程。之前在牛客看到一个小伙伴说:时代的一粒灰尘,落在谁的身上,都将是无法承受之重!深有感触。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务