QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398451#5534. Matchsichengzhou0 0ms3780kbC++141.9kb2024-04-25 12:41:372024-04-25 12:41:38

Judging History

你现在查看的是最新测评结果

  • [2024-04-25 12:41:38]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3780kb
  • [2024-04-25 12:41:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
char ch[N];
int f[N][26],fa[N];
int stk[N],tp;
int vis[N];
struct node{
    int x,y;
    bool operator <(const node &t)const
    {
        if(ch[x]==ch[t.x])
        {
            return x<t.x;
        }
        return ch[x]<ch[t.x];
    }
}a[N];
int tot;
int main()
{
    scanf("%s",ch+1);n=strlen(ch+1);
    for(int i=1;i<=n;i++)
    {
        if(tp>=1&&ch[stk[tp]]-'a'==ch[i]-'a')
        {
            tp--;
        }else{
            stk[++tp]=i;
        }
    }
    if(tp)
    {
        printf("-1");
        return 0;
    }
    fa[n]=0;
    for(int i=n-1;i>=1;i--)
    {
        int x=i+1;
        while(1)
        {
            if(ch[i]==ch[x])
            {
                fa[i]=x+1;break;
            }else{
                if(fa[x]>n||fa[x]==0)
                {
                    fa[i]=0;
                    break;
                }
                x=fa[x];
            }
        }
    //    cout<<i<<' '<<fa[i]<<endl;
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            int cnt=0;
            for(int j=i;j<=n;j=fa[j]-1)
            {
            //    cout<<j<<endl;
                cnt++;
                if(fa[j]==0)
                {
                    break;
                }
            }
            cnt/=2;
            for(int j=i;j<=n;j=fa[j]-1)
            {
                if(cnt)
                {
                    vis[j]=1;
                    cnt--;
                }else{
                    vis[j]=2;
                }
                if(fa[j]==0)
                {
                    break;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==1)
        {
            printf("(");
        }else if(vis[i]==2){
            printf(")");
        }else{
            printf("*");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 3744kb

input:

abbaaa

output:

(()())

result:

ok single line: '(()())'

Test #2:

score: -10
Wrong Answer
time: 0ms
memory: 3780kb

input:

cbbbbccbbccbbbbbbc

output:

((((((((()))))))))

result:

wrong answer 1st lines differ - expected: '(((((((()))())))))', found: '((((((((()))))))))'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%