CF1167D Bicolored RBS solution to a problem [greedy]

# CF1167D Bicolored RBS

Short code greedy

Topic Link (Los Valley)
greedy title.
Meet opening parenthesis minutes into the shallow depth of colors
to meet closing parenthesis divided into deeper color depth
Code really short


code show as below:

#include<bits/stdc++.h>
using namespace std;
const int maxn=2*1e5+10;
int n,rs=0,bs=0;char a[maxn];
int main(){
    scanf("%d%s",&n,a);
    for(int i=0;i<n;i++){
        if(a[i]==')') (rs>bs) ? (--rs,printf("0")) : (--bs,printf("1"));
        else if(a[i]=='(') (rs<bs) ? (++rs,printf("0")) : (++bs,printf("1"));
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/ChrisKKK/p/11599933.html