QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466773 | #7683. Hard Brackets Problem | mango09# | TL | 139ms | 3808kb | C++14 | 415b | 2024-07-08 09:43:55 | 2024-07-08 09:43:55 |
Judging History
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 (()()((((())))(((((((())(()())())()(()((()(((()(()))))())((())((())((()))()())(()))()))((())()())))()())()(()((())(((()()(((())(((()))(((()())((()(((()())()())(()(()(())()()())())(((((((()((((()))()())())((((()(()())()())))((()((((()(((((()((((())()(()(()((((()()(((())())())))(())))))))))((((()(()...