QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591501 | #5534. Match | ifffer_2137 | 10 | 499ms | 3608kb | C++14 | 1.3kb | 2024-09-26 16:11:49 | 2024-09-26 16:11:51 |
Judging History
answer
//From: ifffer_2137
#include <bits/stdc++.h>
using namespace std;
#define inf 0x7fffffff
#define eb emplace_back
#define pii pair<int,int>
#define mkpr make_pair
#define fir first
#define sec second
inline int read(){
char ch=getchar();int x=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-48,ch=getchar();return w==1?x:-x;
}
const int maxn=1e5+5;
int n;
string s;
int stk[maxn],tp;
int ch[maxn];
char ans[maxn];
signed main(){
#ifndef ONLINE_JUDGE
freopen("data.in","r",stdin);
freopen("test.out","w",stdout);
#endif
cin.tie(0),cout.tie(0);
cin>>s;n=s.size();s=' '+s;
for(int i=1;i<=n;i++){
if(tp&&s[stk[tp]]==s[i]) ans[stk[tp]]='(',ans[i]=')',ch[stk[tp]]=i,ch[i]=stk[tp],tp--;
else stk[++tp]=i;
}
if(tp){
puts("-1");
return 0;
}
int T=2000;
while(T--){
for(int i=n;i>=1;i--){
if(ch[i]>i) continue;
tp=0;int pos=0;
for(int j=i;j<n;j++){
if(j>i){
if(ans[j]==')'&&tp&&ans[stk[tp]]=='(') tp--;
else stk[++tp]=j;
}
if(tp) continue;
if(s[j+1]==s[i]&&ch[j+1]>j+1) pos=j+1;
}
if(pos){
ch[ch[i]]=ch[pos],ch[ch[pos]]=ch[i];
ch[i]=pos,ch[pos]=i;
ans[i]='(',ans[pos]=')';
}
}
}
for(int i=1;i<=n;i++) cout<<ans[i];
cout<<"\n";
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 3544kb
input:
abbaaa
output:
(()())
result:
ok single line: '(()())'
Test #2:
score: 10
Accepted
time: 1ms
memory: 3580kb
input:
cbbbbccbbccbbbbbbc
output:
(((((((()))())))))
result:
ok single line: '(((((((()))())))))'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3540kb
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: 499ms
memory: 3608kb
input:
fsooskkkksokkkkossskkiffoofooikkiiiiiooikkkksookkiissiooookskffsskiiksskiikfiifkifofssooffffkfiiiifkfsiisfsofossiffissikskiikkkiikokikkffkiiksffkkiossifkiookioffoikkkoiiiooioiffkkkssfoooiiiioioskksisikkkoifiooikkkkfiffississkskiofffiffiiiosksskfffofisksksskiisikkskkkksoosiffoofoiooioooifiifssfffffoi...
output:
((((((())))(()))(()()(()((((((((((())())()))(((((((())(())(((()())(((()(())(())))(((()()((()(((()))(((()))((((()(()(())((((((()())(((((())())(()()((()(((((((((()))()))(()())))()())())(()(()))))(()))))()))(((())(())))())())())))))())(()()))))())))))))))((())()))))((()))))))())))((())))))(()(()(()))((...
result:
wrong answer 1st lines differ - expected: '((((((())))(()))(((()(((()((((...))(())(()))(())())))))))((())))', found: '((((((())))(()))(()()(()((((((...))(())(()))(())()))))(()())))))'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%