QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#398451 | #5534. Match | sichengzhou | 0 | 0ms | 3780kb | C++14 | 1.9kb | 2024-04-25 12:41:37 | 2024-04-25 12:41:38 |
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%