QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#466773#7683. Hard Brackets Problemmango09#TL 139ms3808kbC++14415b2024-07-08 09:43:552024-07-08 09:43:55

Judging History

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

  • [2024-07-08 09:43:55]
  • 评测
  • 测评结果:TL
  • 用时:139ms
  • 内存:3808kb
  • [2024-07-08 09:43:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
void solve(){
	string s,ans,t;
	cin>>s;int cnt=0,n=s.size();
	for(int i=0;i<n;i++){
		if(s[i]=='('){
			t=t+'(';cnt++;
			ans=ans+'(';
		}else if(cnt){
			ans=ans+')';cnt--;t=t+')';
		}else{
			ans=ans+')';t=t+')';
		}
	}
	while(cnt--)t=t+')';
	if(s==t)cout<<ans<<"\n";
	else cout<<"impossible\n";
}
int main(){
	int T;cin>>T;
	while(T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

3
((()))
(
)))()

output:

((()))
impossible
)))()

result:

ok 3 cases (3 test cases)

Test #2:

score: 0
Accepted
time: 71ms
memory: 3576kb

input:

100000
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
(()())())
())(()))()
(())(())))
))))(()(()
()))(())((
()((())())
()))()))()
()((())())
()()))((()
()))(()))
(()(())))
())((()))
())()((())
(()(())))
()(((()())
))))())))(
((((()()()
(()(...

output:

impossible
()())()))
)()()()()
impossible
((())()))
impossible
)()))())))
impossible
impossible
()((()()))
(()())())
())(()))()
(())(())))
impossible
impossible
()((())())
()))()))()
()((())())
impossible
()))(()))
(()(())))
())((()))
impossible
(()(())))
impossible
impossible
impossible
impossible
...

result:

ok 100000 cases (100000 test cases)

Test #3:

score: 0
Accepted
time: 91ms
memory: 3580kb

input:

200000
(()))
()))(
)()))
(())
)((((
)(())
)(())
()))(
((()(
()(()
))())
)((((
()())
(())
()(()
(()()
)(())
()))
(()()
()())
(())
()()(
(()((
)())
(()()
(())
))(((
(())
())()
())()
(()))
(((((
)())
(()))
()(()
)()()
(()))
()())
(()))
)(())
(())(
))))(
())((
))(((
))))(
()()
()())
(())
(())
(())
)(())...

output:

(()))
impossible
)()))
(())
impossible
)(())
)(())
impossible
impossible
impossible
))())
impossible
()())
(())
impossible
impossible
)(())
()))
impossible
()())
(())
impossible
impossible
)())
impossible
(())
impossible
(())
())()
())()
(()))
impossible
)())
(()))
impossible
)()()
(()))
()())
(()))...

result:

ok 200000 cases (200000 test cases)

Test #4:

score: 0
Accepted
time: 127ms
memory: 3600kb

input:

250000
()()
(())
())
)(((
(()(
(())
)()
(())
(())
))()
)(()
)())
)())
(())
)())
()))
())
(()(
))))
()((
()()
)())
())
())
())
(())
))()
(())
(()(
)))(
()))
())
)))(
)(()
()))
()()
(())
((()
(())
))((
))((
(())
()))
(()(
(())
((()
)(()
(())
((((
())
))()
())
()()
)()(
)()
(())
))()
()))
())
)()
)())
...

output:

()()
(())
())
impossible
impossible
(())
)()
(())
(())
))()
impossible
)())
)())
(())
)())
()))
())
impossible
))))
impossible
()()
)())
())
())
())
(())
))()
(())
impossible
impossible
()))
())
impossible
impossible
()))
()()
(())
impossible
(())
impossible
impossible
(())
()))
impossible
(())
impo...

result:

ok 250000 cases (250000 test cases)

Test #5:

score: 0
Accepted
time: 88ms
memory: 3464kb

input:

50000
)))()((((()(((())(()
)(())()())((())))()(
(((((()))()(((()((()
)()(()())(()())(()()
()(())()()()((())))
)((())))((((())(((((
((())(()()))()(()())
()))())(()))(()())((
))(((())(())()))())
((((()())()))()(((((
((())()))))(((()))))
()()(())((()(()))))
()())())))()()(()))
()))(())()())()(())
()()(...

output:

impossible
impossible
impossible
impossible
()(())()()()((())))
impossible
((())(()()))()(()())
impossible
))(((())(())()))())
impossible
((())()))))(((()))))
()()(())((()(()))))
()())())))()()(()))
()))(())()())()(())
impossible
)))))(())()())((()))
impossible
)(((()())()(())()))
impossible
impossi...

result:

ok 50000 cases (50000 test cases)

Test #6:

score: 0
Accepted
time: 79ms
memory: 3804kb

input:

83333
((()((())(()
(())(()()))
()(()(())))
((((())))))
)())(((())))
()()())()())
()()((())))
(()(()(((())
()((()()()()
(()()()())))
(()()()(((()
)))))()()())
)((()()())))
))(((()))))
()())(()))()
)()))))()())
)(()((())))(
(()())(()))
())()((())))
(()()()(()))
)())()()(())
((())()))(()
(()(()(((())
)...

output:

impossible
(())(()()))
()(()(())))
((((())))))
)())(((())))
()()())()())
()()((())))
impossible
impossible
(()()()())))
impossible
)))))()()())
)((()()())))
))(((()))))
()())(()))()
)()))))()())
impossible
(()())(()))
())()((())))
(()()()(()))
)())()()(())
impossible
impossible
impossible
impossible...

result:

ok 83333 cases (83333 test cases)

Test #7:

score: 0
Accepted
time: 139ms
memory: 3516kb

input:

250000
)))
)(((
()()
((()
((()
())
())(
))((
)())
()()
()()
())
((()
())
()()
(())
(())
()()
()))
())
)())
()()
)()
())
)()(
(())
)()
)(((
))()
(())
)()
)())
)()
)()
))((
()()
(())
()((
))((
)(((
()))
)())
)())
)())
)())
)(((
())
)))
(())
(())
())(
())
(())
(())
()()
())(
()()
())
))()
(())
(())
)()...

output:

)))
impossible
()()
impossible
impossible
())
impossible
impossible
)())
()()
()()
())
impossible
())
()()
(())
(())
()()
()))
())
)())
()()
)()
())
impossible
(())
)()
impossible
))()
(())
)()
)())
)()
)()
impossible
()()
(())
impossible
impossible
impossible
()))
)())
)())
)())
)())
impossible
())...

result:

ok 250000 cases (250000 test cases)

Test #8:

score: 0
Accepted
time: 76ms
memory: 3596kb

input:

50000
(())((()()(())(((()(
()()()((((()())())))
(())(()()()((())))()
(())(()))(()(()()))
()((((()((())))))))
)))())))()()())()))(
()(()))(((())()(((((
()()())())(((()())))
(())(())))(()((())))
()(()(())()()()()(((
()()()((()(()()))))
)(())))()(())()())()
)((((((()())())((())
)()())(()((()(()))))
(()...

output:

impossible
()()()((((()())())))
(())(()()()((())))()
(())(()))(()(()()))
()((((()((())))))))
impossible
impossible
()()())())(((()())))
(())(())))(()((())))
impossible
()()()((()(()()))))
)(())))()(())()())()
impossible
)()())(()((()(()))))
(())(()()())()())())
)())()()()()((())())
(())()((())((()))...

result:

ok 50000 cases (50000 test cases)

Test #9:

score: 0
Accepted
time: 79ms
memory: 3592kb

input:

83333
((()(())))()
()))()()))()
()))()))())(
())(())))())
)()))))(((((
)(()(()())((
(()))(())())
)()()()(()()
((()())((())
)())()()(()(
()(())()())
)(()(())())
()(())(()))
))()(()(())(
()((()())))
)()(((())))
)())()())))
(((()()())))
()())()())()
()())(())()
)()((()())((
(()()((((())
(())))()()))
((...

output:

((()(())))()
()))()()))()
impossible
())(())))())
impossible
impossible
(()))(())())
impossible
impossible
impossible
()(())()())
)(()(())())
()(())(()))
impossible
()((()())))
)()(((())))
)())()())))
(((()()())))
()())()())()
()())(())()
impossible
impossible
(())))()()))
((((())))))
impossible
())...

result:

ok 83333 cases (83333 test cases)

Test #10:

score: 0
Accepted
time: 127ms
memory: 3576kb

input:

250000
)())
()))
())(
(())
()()
())
))((
())
)()
())
()((
()))
(())
)(((
())
(())
))()
)())
(()(
)()
((((
()))
)))(
(()(
()()
))))
)())
()()
((()
)(((
()()
(())
)(()
()()
)()
)))(
())
())(
())
)))(
))()
())
)())
))((
())
()))
((()
)()(
)()
()))
())
)())
(())
(()(
()()
()))
()))
)))(
()))
)()
())
())...

output:

)())
()))
impossible
(())
()()
())
impossible
())
)()
())
impossible
()))
(())
impossible
())
(())
))()
)())
impossible
)()
impossible
()))
impossible
impossible
()()
))))
)())
()()
impossible
impossible
()()
(())
impossible
()()
)()
impossible
())
impossible
())
impossible
))()
())
)())
impossible
...

result:

ok 250000 cases (250000 test cases)

Test #11:

score: 0
Accepted
time: 92ms
memory: 3584kb

input:

50000
(())(()(()(())))())
())()()))(())()()())
())()())((()(()))))
()(()()))(()((())))
()))))()))((()((()))
()(())())())(()))())
((()((()((())))())))
())()))()()()())))))
(((()()))))))()(())
))(()((())((((()((((
()((()()(((()()()())
(()())(()(()))())))
()()))))(()(()()()))
())()())(((()(()))))
()(((...

output:

(())(()(()(())))())
())()()))(())()()())
())()())((()(()))))
()(()()))(()((())))
impossible
()(())())())(()))())
((()((()((())))())))
())()))()()()())))))
(((()()))))))()(())
impossible
impossible
(()())(()(()))())))
()()))))(()(()()()))
())()())(((()(()))))
()((()(()))()(())))
impossible
()))())(()...

result:

ok 50000 cases (50000 test cases)

Test #12:

score: 0
Accepted
time: 84ms
memory: 3596kb

input:

83333
())()))))(()
(()((()(()))
((((((()())(
())(((((()))
((())((())))
)())())))))(
()(((())((()
()(((()))))
(()))((()))
)(())())((((
)()()()(())
)(()))(())))
)(((()())))
)(())(()()))
(())))(()))(
(((((()))))(
))((()()())(
(((()))())()
(((()()((())
())))))(((((
()((((()))))
)()(()))(())
(()))(()()))...

output:

impossible
impossible
impossible
impossible
((())((())))
impossible
impossible
()(((()))))
(()))((()))
impossible
)()()()(())
)(()))(())))
)(((()())))
)(())(()()))
impossible
impossible
impossible
(((()))())()
impossible
impossible
()((((()))))
)()(()))(())
(()))(()()))
)())))()()))
impossible
(())(...

result:

ok 83333 cases (83333 test cases)

Test #13:

score: 0
Accepted
time: 124ms
memory: 3508kb

input:

250000
(())
((((
(())
())
()()
(())
(())
())
))()
(())
))()
(())
()))
))))
(())
()))
()))
())
)()(
)))
)())
(())
(())
))()
(())
())
()))
))()
))((
)()
()()
)(((
(())
()()
)()
)(()
())
)())
((()
))()
)(((
()))
())
())
)())
()))
)())
(())
))()
))))
)())
())
))()
)()(
))))
((((
())
(())
)()
)())
())
()...

output:

(())
impossible
(())
())
()()
(())
(())
())
))()
(())
))()
(())
()))
))))
(())
()))
()))
())
impossible
)))
)())
(())
(())
))()
(())
())
()))
))()
impossible
)()
()()
impossible
(())
()()
)()
impossible
())
)())
impossible
))()
impossible
()))
())
())
)())
()))
)())
(())
))()
))))
)())
())
))()
impo...

result:

ok 250000 cases (250000 test cases)

Test #14:

score: 0
Accepted
time: 85ms
memory: 3564kb

input:

50000
))(())())())()(()(()
)((())((()()))(())))
()(()(()))()(()()))
((()())()())(()(()))
)()()(())())()(())()
(()(()(((())))()()))
((()))()()(()(()((()
()()()()(())(((())))
)))))((((()()()()(((
((())((()()(())))))
(((((()()()(()))))))
())())))())())()(())
((())((((((())))))))
((())()())())()()())
()...

output:

impossible
)((())((()()))(())))
()(()(()))()(()()))
((()())()())(()(()))
)()()(())())()(())()
(()(()(((())))()()))
impossible
()()()()(())(((())))
impossible
((())((()()(())))))
(((((()()()(()))))))
())())))())())()(())
((())((((((())))))))
((())()())())()()())
()((((()(((())))))))
()())(((()))((())...

result:

ok 50000 cases (50000 test cases)

Test #15:

score: 0
Accepted
time: 56ms
memory: 3808kb

input:

83333
)))((())(()(
()((()))())
(()))()(()((
))((()()(()(
(()))()()))
)))()()(()((
)(()))()()((
())((()))))
(())))()())
)(()()))(()(
()(()()))()
()))())())((
((()(()())))
(((())()()()
()(())(()())
))())((()))
())((()()(()
))(()((())))
((((()()))))
(()((())())(
)()())(())()
))(()())()))
(()(())(()()
(...

output:

impossible
()((()))())
impossible
impossible
(()))()()))
impossible
impossible
())((()))))
(())))()())
impossible
()(()()))()
impossible
((()(()())))
impossible
()(())(()())
))())((()))
impossible
))(()((())))
((((()()))))
impossible
)()())(())()
))(()())()))
impossible
())(())()()
impossible
imposs...

result:

ok 83333 cases (83333 test cases)

Test #16:

score: -100
Time Limit Exceeded

input:

1
(()()((((())))(((((((())(()())())()(()((()(((()(()))))())((())((())((()))()())(()))()))((())()())))()())()(()((())(((()()(((())(((()))(((()())((()(((()())()())(()(()(())()()())())(((((((()((((()))()())())((((()(()())()())))((()((((()(((((()((((())()(()(()((((()()(((())())())))(())))))))))((((()(()...

output:


result: