Educational Codeforces Round 65 (Rated for Div. 2) D - Bicolored RBS (前缀和,括号序列)

😻 😻 😻

套路题,转换成1,-1序列,最大前缀和就是最大深度,然后对半分即可,只要前缀和大于二分之一前缀和+1,就输出0,其他都是1

int sum[MAXN];
signed main()
{
    int n;cin>>n;
    string s;cin>>s;
    int mx=0;
    rep(i,n)
    {
        if(i==0) sum[i] = (s[i] =='('?1:-1);
        else sum[i] = sum[i-1] +  (s[i] =='('?1:-1);
        mx= max(mx,sum[i]);
    }
    int tag=mx/2+1;
    rep(i,n)
    {
        if(sum[i] ==tag)
        {
            while(sum[i++]!=tag-1) cout<<0;
            cout<<0;
            --i;
        }
        else cout<<1;
    }
    cout<<endl;
    return 0;
}
posted @ 2020-01-29 17:57  Herlo  阅读(85)  评论(0)    收藏  举报