[Offer收割]编程练习赛41 register

Ended

Participants:163

Verdict:Accepted
Score:100 / 100
Submitted:2017-12-24 14:19:21

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
using namespace std;
const int MAX=6e6;
const int MOD=1e9+7;
typedef long long ll;
char s[MAX];
int suf[MAX],pre[MAX];
void dfs(int x,int y,int tag)
{
    if(tag==0)
    {
        for(int i=x;i<=y;i++)
        {
            if(s[i]!='(')printf("%c",s[i]);
            else
            {
                if(suf[i]-1>=i+1)dfs(i+1,suf[i]-1,1);
                if(suf[i]+1<=y)dfs(suf[i]+1,y,0);
                return;
            }
        }
    }
    else
    {
        for(int i=y;i>=x;i--)
        {
            if(s[i]!=')')printf("%c",s[i]);
            else
            {
                if(pre[i]+1<=i-1)dfs(pre[i]+1,i-1,0);
                if(pre[i]-1>=x)dfs(x,pre[i]-1,1);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX