建树, 然后高度最大值的最小值显然为$\lceil \frac{dep}{2}\rceil$, 将$>\frac{dep}{2}$的全部分出去即可.

#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e6+10;
int n, tot, now, mx;
char s[N], Ans[N];
vector<int> g[N];
int L[N], R[N], dep[N]; void dfs(int x) {
while (s[now]=='(') {
L[tot+1]=now;
++now,g[x].pb(++tot),dfs(tot);
}
R[x]=now++;
}
void dfs(int x, int d) {
mx=max(mx,dep[x]=d);
for (int y:g[x]) dfs(y,d+1);
}
int main() {
scanf("%d%s", &n, s+1);
now=tot=1,dfs(1),dfs(1,0);
memset(Ans,'0',sizeof Ans);
REP(i,1,tot) if (dep[i]>mx/2) Ans[L[i]]=Ans[R[i]]='1';
Ans[n+1]=0;
puts(Ans+1);
}

Bicolored RBS CodeForces - 1167D (括号)的更多相关文章

  1. Codeforces 1167D - Bicolored RBS

    题目链接:http://codeforces.com/problemset/problem/1167/D 题意:题目定义RBS,给你一个字符串,你要对其所有字符染色,使之分解为俩个RBS,使俩个RBS ...

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

    链接:https://codeforces.com/contest/1167/problem/D 题意: A string is called bracket sequence if it does ...

  3. The Monster CodeForces - 917A (括号匹配)

    链接 大意:给定字符串, 只含'(',')','?', 其中'?'可以替换为'('或')', 求有多少个子串可以的括号可以匹配 (不同子串之间独立) 记$s_($为'('个数, $s_)$为')'个数 ...

  4. Neko and Aki's Prank CodeForces - 1152D (括号序列,dp)

    大意: 将所有长度为2*n的合法括号序列建成一颗trie树, 求trie树上选出一个最大不相交的边集, 输出边集大小. 最大边集数一定不超过奇数层结点数. 这个上界可以通过从底层贪心达到, 所以就转化 ...

  5. Bracket Sequences Concatenation Problem CodeForces - 990C(括号匹配水题)

    明确一下  一个字符串有x左括号不匹配  和 另一个字符串有x个右括号不匹配  这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了  统计x个左括号的有几个,x个右括号的有几个 然后 乘一 ...

  6. [CF1167D]Bicolored RBS题解

    模拟两个颜色的扩号层数,贪心,如果是左括号,哪边的层数浅就放那边:如果是右括号,哪边的层数深就放那边. 至于层数的维护,两个int就做掉了 放个代码: #include <cstdio> ...

  7. Codeforces 918 括号匹配 SGdp[i][j][k]

    A B C #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) ...

  8. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  9. codeforces Educational Codeforces Round 65 (补完)

    C News Distribution 并查集水题 D Bicolored RBS 括号匹配问题,如果给出的括号序列nesting depth为n,那么最终可以分成两个nesting depth为n ...

随机推荐

  1. 输出变量的界值(int、float、long.....)

    //整型.浮点型变量表示的关键字,并给出它们各自的界值 #include<iostream> #include<climits> //包含整型数据范围的头文件 #include ...

  2. linux rpm包管理 yum管理

    1. 软件包的管理 RPM的定义:RPM就是Red Hat Package Manger(红帽软件包管理工具)的缩写. RPM包不需要编译,本身就是二进制,而源码包需要先编译成系统识别的二进制文件,才 ...

  3. Java - 可循环队列

    队列是一种特殊的线性表,是一种先进先出的数据结构.只允许在表的前端进行删除操作,在表的后端进行插入操作.进行插入操作的端称为队尾,进行删除操作的端称为队头.队列中没有元素时,称为空队列. 简单的循环队 ...

  4. STL -- heap结构及算法

    STL -- heap结构及算法 heap(隐式表述,implicit representation) 1. heap概述 : vector + heap算法 heap并不归属于STL容器组件,它是个 ...

  5. [eclipse]如何修改Eclipse编辑器的字体

    步骤如下, 菜单->"Window"->“Preference”->“General”->“Appearance”->“Colors & Fo ...

  6. C# 防火墙操作之开启与关闭

    通过代码操作防火墙的方式有两种:一是代码操作修改注册表启用或关闭防火墙:二是直接操作防火墙对象来启用或关闭防火墙.不论哪一种方式,都需要使用管理员权限,所以操作前需要判断程序是否具有管理员权限. 1. ...

  7. 小程序API:wx.showActionSheet 将 itemList动态赋值

    1.发现问题: 小程序调用API:wx.showActionSheet 时发现无论如何都不能将其属性itemList动态赋值. 2.分析问题: 首先我认为可能是格式的问题,itemList必须要求格式 ...

  8. 阶段3 3.SpringMVC·_02.参数绑定及自定义类型转换_5 自定义类型转换器演示异常

    后端自动进行类型的转换.前端输入的年龄都是字符串的形式传递到后端. user的实体类  加一个Date日期类型格式的字段.生成get和set还有toString的方法 重新部署程序 日期用横线的方式 ...

  9. MySQL随机字符串函数批量插入数据

      简单举个例子: drop table if exists demo1 create table demo1 ( id int primary key auto_increment, name ) ...

  10. 日期格式存入字符类型之后,再转回datetime类型报错

    背景 最近我们迁移了一批服务器,因我们在azure portal 上新开的VM暂时默认只有英文系统,所以我们在开设好的数据库服务器的时候,都会重置数据库字符排序成中文,避免出现中文乱码问题,重置参考路 ...