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

D. Bicolored RBS

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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

2
()

output

11

input

4
(())

output

0101

input

10
((()())())

output

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.

题意:

大致意思是将括号分成两队,使两队的嵌入值(也就是内括号的数量)的最大值最小。

思路:

这道题的思路是两队分的嵌入值是原本的一半就行。

总体上是暴力流,主要是有 2 seconds,所以不用担心超时问题。

这道题的代码大致思路是将 ’ ( ’ 标记出是几级嵌入,然后将是最大嵌入值除以2,是将凡是小于最大嵌入值一半的变成0,不是的变成1,然后在变1的时候sum++,统计接下来需要几个 ’ ) ’ ,只要sum不等于0,那么接下来一旦遇到 ’ ) ’ ,就变1。

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
ll a[2000030];
int main(){
	string s;ll n,i;
	while(cin>>n>>s){
		mes(a,0);ll maxn=-1,sum=0;//先让全部为0,设一个统计最大值的变量,和一个标记的变量
		for(i=0;i<n;i++){
			if(s[i]=='('){
				sum++;
				a[i]=sum;
			}
			else{
				sum--;
			}
			if(sum>maxn)maxn=sum;
		}//给每个 ' ( ' 标记嵌入值是多少,并找到最大嵌入值
		maxn/=2;sum=0;//将最大嵌入值除一半,并再次利用sum
		for(i=0;i<n;i++){
			if(s[i]==')'&&sum!=0){
				a[i]=1;sum--;continue;
			}//只要sum不等于0,那么接下来一旦遇到 ' ) ' ,就变1。
			if(a[i]<=maxn){
				a[i]=0;
			}//凡是小于最大嵌入值一半的变成0
			else if(a[i]>maxn){
				sum++;
				a[i]=1;
			}//不是的变成1,然后在变1的时候sum++,统计接下来需要几个 ' ) ' 
		}
		for(i=0;i<n;i++)cout<<a[i];
		cout<<endl;
	} 
} 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值