Bicolored RBS CodeForces - 1167D (括号)
建树, 然后高度最大值的最小值显然为$\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 (括号)的更多相关文章
- Codeforces 1167D - Bicolored RBS
题目链接:http://codeforces.com/problemset/problem/1167/D 题意:题目定义RBS,给你一个字符串,你要对其所有字符染色,使之分解为俩个RBS,使俩个RBS ...
- 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 ...
- The Monster CodeForces - 917A (括号匹配)
链接 大意:给定字符串, 只含'(',')','?', 其中'?'可以替换为'('或')', 求有多少个子串可以的括号可以匹配 (不同子串之间独立) 记$s_($为'('个数, $s_)$为')'个数 ...
- Neko and Aki's Prank CodeForces - 1152D (括号序列,dp)
大意: 将所有长度为2*n的合法括号序列建成一颗trie树, 求trie树上选出一个最大不相交的边集, 输出边集大小. 最大边集数一定不超过奇数层结点数. 这个上界可以通过从底层贪心达到, 所以就转化 ...
- Bracket Sequences Concatenation Problem CodeForces - 990C(括号匹配水题)
明确一下 一个字符串有x左括号不匹配 和 另一个字符串有x个右括号不匹配 这俩是一定能够匹配的 脑子有点迷 emm... 所以统计就好了 统计x个左括号的有几个,x个右括号的有几个 然后 乘一 ...
- [CF1167D]Bicolored RBS题解
模拟两个颜色的扩号层数,贪心,如果是左括号,哪边的层数浅就放那边:如果是右括号,哪边的层数深就放那边. 至于层数的维护,两个int就做掉了 放个代码: #include <cstdio> ...
- 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)) ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- codeforces Educational Codeforces Round 65 (补完)
C News Distribution 并查集水题 D Bicolored RBS 括号匹配问题,如果给出的括号序列nesting depth为n,那么最终可以分成两个nesting depth为n ...
随机推荐
- tomcat配置加密的连接器https
对称加密:加密和解密用的是同样的密钥. 非对称加密:使用一对密钥,公钥和私钥,私钥只由一方保管,不能外泄:公钥可以发给任何请求它的人 那么得到公钥的一方怎么确定这个公钥是服务器发过来的呢? 这个就需要 ...
- (九)C语言之scanf
- uniapp导航栏自定义按钮及点击事件
本文链接:https://blog.csdn.net/qq_33807889/article/details/89945674第一步:显示按钮假设页面名称为:AddSort 在pages.json中找 ...
- sscanf(char*,char*,,,,) sprintf(char*," ",,,);
从字符串读取格式化输入 输入到字符串中
- LeetCode 114. 二叉树展开为链表(Flatten Binary Tree to Linked List)
题目描述 给定一个二叉树,原地将它展开为链表. 例如,给定二叉树 1 / \ 2 5 / \ \ 3 4 6 将其展开为: 1 \ 2 \ 3 \ 4 \ 5 \ 6 解题思路 二叉树转化为链表的基本 ...
- How to change the button text of <input type=“file” />?
How to change the button text of <input type=“file” />? Simply <label class="btn btn-p ...
- Spring核心内容-认识bean
- 网络配置及一些shell命令概览
一.临时配置网络(ip,网关,dns)+永久配置 1.临时配置网络IP地址命令为“ifconfig 网卡名 ip地址/24”,例如: ifconfig eth0 192.168.16.253/24 2 ...
- find 命令详细解释
命令格式:find pathname -options [-print -exec -ok ...] 命令参数: pathname: find命令所查找的目录路径.例如用.来表示当前目录,用/来表示系 ...
- redis数据类型为key的常用命令
redis默认自带16个库select 7切换到redis第8个数据库dbsize查看reids有几个keykeys *查看所有k,vclear清空控制台FLUSHDB清空当前数据库的kvFLUSHA ...