QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#398470 | #5534. Match | sichengzhou | 0 | 0ms | 3772kb | C++14 | 2.6kb | 2024-04-25 13:20:49 | 2024-04-25 13:20:51 |
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(tp==0&&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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3772kb
input:
abbaaa
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%