QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#466882 | #7683. Hard Brackets Problem | adanmaip# | WA | 16ms | 3512kb | C++14 | 731b | 2024-07-08 11:34:38 | 2024-07-08 11:34:39 |
Judging History
answer
#include <cstdio>
#include <cstdlib>
#include <list>
char a[1000000];
char ans[1000000];
int n;
int getl(char* p){
int i=0;
char c=0;
while (c!='('&&c!=')') c=getchar();
while (c=='('||c==')') {
p[i++]=c;
c=getchar();
}
return i;
}
int main(){
int T;
scanf("%d", &T);
while(T--){
for (int i=0; a[i]!=0; ++i) a[i]=0;
for (int i=0; ans[i]!=0; ++i) ans[i]=0;
n=getl(a);
int ansi=0;
int cntlft=0;
for (int i=0; i<n; ++i){
if (a[i]=='('){
++cntlft;
ans[ansi++]='(';
}
else if (a[i]==')'){
if (cntlft>0) --cntlft;
ans[ansi++]=')';
}
}
if (cntlft>0) {
printf("impossible\n");
continue;
}
else printf("%s\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1516kb
input:
3 ((())) ( )))()
output:
((())) impossible )))()
result:
ok 3 cases (3 test cases)
Test #2:
score: 0
Accepted
time: 11ms
memory: 1552kb
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: 11ms
memory: 1544kb
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: 13ms
memory: 1612kb
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: 6ms
memory: 1576kb
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: 11ms
memory: 1588kb
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: 16ms
memory: 1532kb
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: 3ms
memory: 1528kb
input:
50000 (())((()()(())(((()( ()()()((((()())()))) (())(()()()((())))() (())(()))(()(()())) ()((((()((()))))))) )))())))()()())()))( ()(()))(((())()((((( ()()())())(((()()))) (())(())))(()((()))) ()(()(())()()()()((( ()()()((()(()())))) )(())))()(())()())() )((((((()())())((()) )()())(()((()(())))) (()...
output:
impossible ()()()((((()())()))) (())(()()()((())))() (())(()))(()(()())) ()((((()((()))))))) impossible impossible ()()())())(((()()))) (())(())))(()((()))) impossible ()()()((()(()())))) )(())))()(())()())() impossible )()())(()((()(())))) (())(()()())()())()) )())()()()()((())()) (())()((())((()))...
result:
ok 50000 cases (50000 test cases)
Test #9:
score: 0
Accepted
time: 10ms
memory: 1572kb
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: 16ms
memory: 1540kb
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: 10ms
memory: 1500kb
input:
50000 (())(()(()(())))()) ())()()))(())()()()) ())()())((()(())))) ()(()()))(()((()))) ()))))()))((()((())) ()(())())())(()))()) ((()((()((())))()))) ())()))()()()()))))) (((()()))))))()(()) ))(()((())((((()(((( ()((()()(((()()()()) (()())(()(()))()))) ()()))))(()(()()())) ())()())(((()(())))) ()(((...
output:
(())(()(()(())))()) ())()()))(())()()()) ())()())((()(())))) ()(()()))(()((()))) impossible ()(())())())(()))()) ((()((()((())))()))) ())()))()()()()))))) (((()()))))))()(()) impossible impossible (()())(()(()))()))) ()()))))(()(()()())) ())()())(((()(())))) ()((()(()))()(()))) impossible ()))())(()...
result:
ok 50000 cases (50000 test cases)
Test #12:
score: 0
Accepted
time: 10ms
memory: 1580kb
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: 16ms
memory: 1572kb
input:
250000 (()) (((( (()) ()) ()() (()) (()) ()) ))() (()) ))() (()) ())) )))) (()) ())) ())) ()) )()( ))) )()) (()) (()) ))() (()) ()) ())) ))() ))(( )() ()() )((( (()) ()() )() )(() ()) )()) ((() ))() )((( ())) ()) ()) )()) ())) )()) (()) ))() )))) )()) ()) ))() )()( )))) (((( ()) (()) )() )()) ()) ()...
output:
(()) impossible (()) ()) ()() (()) (()) ()) ))() (()) ))() (()) ())) )))) (()) ())) ())) ()) impossible ))) )()) (()) (()) ))() (()) ()) ())) ))() impossible )() ()() impossible (()) ()() )() impossible ()) )()) impossible ))() impossible ())) ()) ()) )()) ())) )()) (()) ))() )))) )()) ()) ))() impo...
result:
ok 250000 cases (250000 test cases)
Test #14:
score: 0
Accepted
time: 10ms
memory: 1616kb
input:
50000 ))(())())())()(()(() )((())((()()))(()))) ()(()(()))()(()())) ((()())()())(()(())) )()()(())())()(())() (()(()(((())))()())) ((()))()()(()(()((() ()()()()(())(((()))) )))))((((()()()()((( ((())((()()(()))))) (((((()()()(())))))) ())())))())())()(()) ((())((((((()))))))) ((())()())())()()()) ()...
output:
impossible )((())((()()))(()))) ()(()(()))()(()())) ((()())()())(()(())) )()()(())())()(())() (()(()(((())))()())) impossible ()()()()(())(((()))) impossible ((())((()()(()))))) (((((()()()(())))))) ())())))())())()(()) ((())((((((()))))))) ((())()())())()()()) ()((((()(((()))))))) ()())(((()))((())...
result:
ok 50000 cases (50000 test cases)
Test #15:
score: 0
Accepted
time: 11ms
memory: 1552kb
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: 0
Accepted
time: 7ms
memory: 3464kb
input:
1 (()()((((())))(((((((())(()())())()(()((()(((()(()))))())((())((())((()))()())(()))()))((())()())))()())()(()((())(((()()(((())(((()))(((()())((()(((()())()())(()(()(())()()())())(((((((()((((()))()())())((((()(()())()())))((()((((()(((((()((((())()(()(()((((()()(((())())())))(())))))))))((((()(()...
output:
impossible
result:
ok 1 cases (1 test case)
Test #17:
score: 0
Accepted
time: 3ms
memory: 2528kb
input:
2 ())())()()(((()))()(((()())(())))))((()((()()()()()())(()((((()))()()((())()()((()))()())(())))(()(())(()()())(())))()())((((()()(()))((())()(())))))(((()(((((()(())()()((())))))(()(()())))))((())))))())())()()(()(()()))(((()))(()())))(())()))()())()()())()((()((()())())))())())((()((()())())(((()...
output:
())())()()(((()))()(((()())(())))))((()((()()()()()())(()((((()))()()((())()()((()))()())(())))(()(())(()()())(())))()())((((()()(()))((())()(())))))(((()(((((()(())()()((())))))(()(()())))))((())))))())())()()(()(()()))(((()))(()())))(())()))()())()()())()((()((()())())))())())((()((()())())(((()))...
result:
ok 2 cases (2 test cases)
Test #18:
score: 0
Accepted
time: 8ms
memory: 3512kb
input:
1 ()(()(()))()()()((()())(())())())()(())(()()(()))(())()()()((()(()(())(()()(()((((()()))))))())((()))))((())((((()))(((((()(()))(((())((()))()()((()(()((()((()()()))(())))(())())()()))))((((()(())))))((()(()((()()())())())(()())(()()))()((((()))())()(((()(())))()()((((()))))()))()()))))((())((()((...
output:
()(()(()))()()()((()())(())())())()(())(()()(()))(())()()()((()(()(())(()()(()((((()()))))))())((()))))((())((((()))(((((()(()))(((())((()))()()((()(()((()((()()()))(())))(())())()()))))((((()(())))))((()(()((()()())())())(()())(()()))()((((()))())()(((()(())))()()((((()))))()))()()))))((())((()(()(...
result:
ok 1 cases (1 test case)
Test #19:
score: 0
Accepted
time: 4ms
memory: 3492kb
input:
1 ()((()(((()))(())()())((()((()))((()()((()())(())())())(()()()()())(())(()((()(((())()((()((((((((())(()))))(((()()(()))(((()()())(()()(())))((((())()(()((()(())))()((())((((())())(()()()(()())((())(((()(((()))((()((()(()))))))())((())))((()))(((())))))))())(((((()(((())))(()())()()(())()(())(()()...
output:
()((()(((()))(())()())((()((()))((()()((()())(())())())(()()()()())(())(()((()(((())()((()((((((((())(()))))(((()()(()))(((()()())(()()(())))((((())()(()((()(())))()((())((((())())(()()()(()())((())(((()(((()))((()((()(()))))))())((())))((()))(((())))))))())(((((()(((())))(()())()()(())()(())(()())(...
result:
ok 1 cases (1 test case)
Test #20:
score: -100
Wrong Answer
time: 4ms
memory: 3480kb
input:
1 )()((((())()))(())()))()(()))()())()(((()()(()(())))(()(((()))(((()()()))())))(())())()))(()((()))())()()()((((()))())))())((()())(()())))(((()(())()((()())(()((((())))(())))(()(())())(())(()()))(()((((()(())((())()()(((())()))(((()))(()(())(()()()()()()(())(((()()()(()(()(()))(()()))(((()((()()((...
output:
)()((((())()))(())()))()(()))()())()(((()()(()(())))(()(((()))(((()()()))())))(())())()))(()((()))())()()()((((()))())))())((()())(()())))(((()(())()((()())(()((((())))(())))(()(())())(())(()()))(()((((()(())((())()()(((())()))(((()))(()(())(()()()()()()(())(((()()()(()(()(()))(()()))(((()((()()(())...
result:
wrong answer the output is too long (test case 1)