QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#398468#5534. Matchsichengzhou10 1ms5860kbC++142.6kb2024-04-25 13:18:162024-04-25 13:18:17

Judging History

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

  • [2024-04-25 13:18:17]
  • 评测
  • 测评结果:10
  • 用时:1ms
  • 内存:5860kb
  • [2024-04-25 13:18:16]
  • 提交

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 mx=0;tp=0;
            for(int j=i+1;j<=n;j++)
            {
                if(vis[j])
                {
                    break;
                }
                if(tp&&ch[j]-'a'==stk[tp])
                {
                    tp--;
                }else{
                    if(ch[j]==ch[i])
                    {
                        mx=j;
                    }
                    stk[++tp]=j;
                }
            }
            vis[i]=1;vis[mx]=2;
        }
    }
    /*
    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;
                }
            }
            cout<<endl;
            while(cnt%2);
            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: 10
Accepted

Test #1:

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

input:

abbaaa

output:

(()())

result:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

cbbbbccbbccbbbbbbc

output:

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

result:

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

Test #3:

score: 0
Accepted
time: 0ms
memory: 3740kb

input:

ddbcbdacccbddaba

output:

-1

result:

ok single line: '-1'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 5860kb

input:

fsooskkkksokkkkossskkiffoofooikkiiiiiooikkkksookkiissiooookskffsskiiksskiikfiifkifofssooffffkfiiiifkfsiisfsofossiffissikskiikkkiikokikkffkiiksffkkiossifkiookioffoikkkoiiiooioiffkkkssfoooiiiioioskksisikkkoifiooikkkkfiffississkskiofffiffiiiosksskfffofisksksskiisikkskkkksoosiffoofoiooioooifiifssfffffoi...

output:

((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())())()((())())())((())(())((()())()())))()((()(())()((()(()((()((()())(())((()(())()()((((((())())(((()(())()(((()()(()()(((())))())(((())((())())((()(()(()))((...

result:

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

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%