QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467090 | #7683. Hard Brackets Problem | adanmaip# | WA | 16ms | 3528kb | C++14 | 861b | 2024-07-08 13:49:11 | 2024-07-08 13:49:11 |
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;
bool flag=0;
for (int i=0; i<n; ++i){
flag=0;
if (a[i]=='('){
++cntlft;
ans[ansi++]='(';
}
else if (a[i]==')'){
if (cntlft>0) {
--cntlft;
if (cntlft==0) flag=1;
}
ans[ansi++]=')';
}
}
if (cntlft>0) {
printf("impossible\n");
continue;
}
--ansi;
if (flag) while (ans[ansi]==')') ans[ansi--]=0;
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: 1584kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: 0
Accepted
time: 11ms
memory: 1520kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())())) )()()()( 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: 15ms
memory: 1520kb
input:
200000 (())) ()))( )())) (()) )(((( )(()) )(()) ()))( ((()( ()(() ))()) )(((( ()()) (()) ()(() (()() )(()) ())) (()() ()()) (()) ()()( (()(( )()) (()() (()) ))((( (()) ())() ())() (())) ((((( )()) (())) ()(() )()() (())) ()()) (())) )(()) (())( ))))( ())(( ))((( ))))( ()() ()()) (()) (()) (()) )(())...
output:
(())) impossible )())) (( impossible )(( )(( impossible impossible impossible ))()) impossible ()()) (( impossible impossible )(( ())) impossible ()()) (( impossible impossible )()) impossible (( impossible (( ())( ())( (())) impossible )()) (())) impossible )()( (())) ()()) (())) )(( impossible imp...
result:
ok 200000 cases (200000 test cases)
Test #4:
score: 0
Accepted
time: 16ms
memory: 1524kb
input:
250000 ()() (()) ()) )((( (()( (()) )() (()) (()) ))() )(() )()) )()) (()) )()) ())) ()) (()( )))) ()(( ()() )()) ()) ()) ()) (()) ))() (()) (()( )))( ())) ()) )))( )(() ())) ()() (()) ((() (()) ))(( ))(( (()) ())) (()( (()) ((() )(() (()) (((( ()) ))() ()) ()() )()( )() (()) ))() ())) ()) )() )()) ...
output:
()( (( ()) impossible impossible (( )( (( (( ))( impossible )()) )()) (( )()) ())) ()) impossible )))) impossible ()( )()) ()) ()) ()) (( ))( (( impossible impossible ())) ()) impossible impossible ())) ()( (( impossible (( impossible impossible (( ())) impossible (( impossible impossible (( impossi...
result:
ok 250000 cases (250000 test cases)
Test #5:
score: 0
Accepted
time: 10ms
memory: 1540kb
input:
50000 )))()((((()(((())(() )(())()())((())))()( (((((()))()(((()((() )()(()())(()())(()() ()(())()()()((()))) )((())))((((())((((( ((())(()()))()(()()) ()))())(()))(()())(( ))(((())(())()))()) ((((()())()))()((((( ((())()))))(((())))) ()()(())((()(())))) ()())())))()()(())) ()))(())()())()(()) ()()(...
output:
impossible impossible impossible impossible ()(())()()()((()))) impossible ((())(()()))()(()( impossible ))(((())(())()))()) impossible ((())()))))(((())))) ()()(())((()(())))) ()())())))()()(())) ()))(())()())()(( impossible )))))(())()())((( impossible )(((()())()(())( impossible impossible imposs...
result:
ok 50000 cases (50000 test cases)
Test #6:
score: 0
Accepted
time: 7ms
memory: 1512kb
input:
83333 ((()((())(() (())(()())) ()(()(()))) ((((()))))) )())(((()))) ()()())()()) ()()((()))) (()(()(((()) ()((()()()() (()()()()))) (()()()(((() )))))()()()) )((()()()))) ))(((())))) ()())(()))() )()))))()()) )(()((())))( (()())(())) ())()((()))) (()()()(())) )())()()(()) ((())()))(() (()(()(((()) )...
output:
impossible (())(()())) ()(()(()))) ((((()))))) )())(((( ()()())()()) ()()((()))) impossible impossible (()()()()))) impossible )))))()()()) )((()()()))) ))(((())))) ()())(()))( )()))))()()) impossible (()())(())) ())()((()))) (()()()(( )())()()(( impossible impossible impossible impossible impossibl...
result:
ok 83333 cases (83333 test cases)
Test #7:
score: 0
Accepted
time: 12ms
memory: 1588kb
input:
250000 ))) )((( ()() ((() ((() ()) ())( ))(( )()) ()() ()() ()) ((() ()) ()() (()) (()) ()() ())) ()) )()) ()() )() ()) )()( (()) )() )((( ))() (()) )() )()) )() )() ))(( ()() (()) ()(( ))(( )((( ())) )()) )()) )()) )()) )((( ()) ))) (()) (()) ())( ()) (()) (()) ()() ())( ()() ()) ))() (()) (()) )()...
output:
))) impossible ()( 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: 10ms
memory: 1540kb
input:
50000 (())((()()(())(((()( ()()()((((()())()))) (())(()()()((())))() (())(()))(()(()())) ()((((()((()))))))) )))())))()()())()))( ()(()))(((())()((((( ()()())())(((()()))) (())(())))(()((()))) ()(()(())()()()()((( ()()()((()(()())))) )(())))()(())()())() )((((((()())())((()) )()())(()((()(())))) (()...
output:
impossible ()()()((((()())( (())(()()()((())))( (())(()))(()(()( ()((((()((()))))))) impossible impossible ()()())())(((()( (())(())))(()((( impossible ()()()((()(()())))) )(())))()(())()())( impossible )()())(()((()(( (())(()()())()())()) )())()()()()((())( (())()((())((())))) ))()))(()()))())))( )...
result:
ok 50000 cases (50000 test cases)
Test #9:
score: 0
Accepted
time: 11ms
memory: 1532kb
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: 1588kb
input:
250000 )()) ())) ())( (()) ()() ()) ))(( ()) )() ()) ()(( ())) (()) )((( ()) (()) ))() )()) (()( )() (((( ())) )))( (()( ()() )))) )()) ()() ((() )((( ()() (()) )(() ()() )() )))( ()) ())( ()) )))( ))() ()) )()) ))(( ()) ())) ((() )()( )() ())) ()) )()) (()) (()( ()() ())) ())) )))( ())) )() ()) ())...
output:
)()) ())) impossible (( ()( ()) impossible ()) )( ()) impossible ())) (( impossible ()) (( ))( )()) impossible )( impossible ())) impossible impossible ()( )))) )()) ()( impossible impossible ()( (( impossible ()( )( impossible ()) impossible ()) impossible ))( ()) )()) impossible ()) ())) impossibl...
result:
ok 250000 cases (250000 test cases)
Test #11:
score: 0
Accepted
time: 5ms
memory: 1484kb
input:
50000 (())(()(()(())))()) ())()()))(())()()()) ())()())((()(())))) ()(()()))(()((()))) ()))))()))((()((())) ()(())())())(()))()) ((()((()((())))()))) ())()))()()()()))))) (((()()))))))()(()) ))(()((())((((()(((( ()((()()(((()()()()) (()())(()(()))()))) ()()))))(()(()()())) ())()())(((()(())))) ()(((...
output:
(())(()(()(())))()) ())()()))(())()()()) ())()())((()(())))) ()(()()))(()((( impossible ()(())())())(()))()) ((()((()((())))( ())()))()()()()))))) (((()()))))))()(( impossible impossible (()())(()(()))()))) ()()))))(()(()()( ())()())(((()(( ()((()(()))()(()))) impossible ()))())(())(((( ())(((()))()...
result:
ok 50000 cases (50000 test cases)
Test #12:
score: 0
Accepted
time: 11ms
memory: 1560kb
input:
83333 ())()))))(() (()((()(())) ((((((()())( ())(((((())) ((())((()))) )())())))))( ()(((())((() ()(((())))) (()))((())) )(())())(((( )()()()(()) )(()))(()))) )(((()()))) )(())(()())) (())))(()))( (((((()))))( ))((()()())( (((()))())() (((()()((()) ())))))((((( ()((((())))) )()(()))(()) (()))(()()))...
output:
impossible impossible impossible impossible ((())((( impossible impossible ()(((())))) (()))((( impossible )()()()(( )(()))(()))) )(((()( )(())(()())) impossible impossible impossible (((()))())( impossible impossible ()((((( )()(()))(( (()))(()())) )())))()())) impossible (())(()()( ()(()((( imposs...
result:
ok 83333 cases (83333 test cases)
Test #13:
score: 0
Accepted
time: 16ms
memory: 1552kb
input:
250000 (()) (((( (()) ()) ()() (()) (()) ()) ))() (()) ))() (()) ())) )))) (()) ())) ())) ()) )()( ))) )()) (()) (()) ))() (()) ()) ())) ))() ))(( )() ()() )((( (()) ()() )() )(() ()) )()) ((() ))() )((( ())) ()) ()) )()) ())) )()) (()) ))() )))) )()) ()) ))() )()( )))) (((( ()) (()) )() )()) ()) ()...
output:
(( impossible (( ()) ()( (( (( ()) ))( (( ))( (( ())) )))) (( ())) ())) ()) impossible ))) )()) (( (( ))( (( ()) ())) ))( impossible )( ()( impossible (( ()( )( impossible ()) )()) impossible ))( impossible ())) ()) ()) )()) ())) )()) (( ))( )))) )()) ()) ))( impossible )))) impossible ()) (( )( )()...
result:
ok 250000 cases (250000 test cases)
Test #14:
score: 0
Accepted
time: 10ms
memory: 1532kb
input:
50000 ))(())())())()(()(() )((())((()()))(()))) ()(()(()))()(()())) ((()())()())(()(())) )()()(())())()(())() (()(()(((())))()())) ((()))()()(()(()((() ()()()()(())(((()))) )))))((((()()()()((( ((())((()()(()))))) (((((()()()(())))))) ())())))())())()(()) ((())((((((()))))))) ((())()())())()()()) ()...
output:
impossible )((())((()()))(()))) ()(()(()))()(()())) ((()())()())(()(( )()()(())())()(())( (()(()(((())))()( impossible ()()()()(())(((( impossible ((())((()()(()))))) (((((()()()(( ())())))())())()(( ((())((((((( ((())()())())()()()) ()((((()(((( ()())(((()))((())))) impossible ))))))(())()(((( ()()...
result:
ok 50000 cases (50000 test cases)
Test #15:
score: 0
Accepted
time: 11ms
memory: 1532kb
input:
83333 )))((())(()( ()((()))()) (()))()(()(( ))((()()(()( (()))()())) )))()()(()(( )(()))()()(( ())((())))) (())))()()) )(()()))(()( ()(()()))() ()))())())(( ((()(()()))) (((())()()() ()(())(()()) ))())((())) ())((()()(() ))(()((()))) ((((()())))) (()((())())( )()())(())() ))(()())())) (()(())(()() (...
output:
impossible ()((()))()) impossible impossible (()))()())) impossible impossible ())((())))) (())))()()) impossible ()(()()))( impossible ((()(()( impossible ()(())(()( ))())((( impossible ))(()((( ((((()( impossible )()())(())( ))(()())())) impossible ())(())()( impossible impossible ))()(())()) ()((...
result:
ok 83333 cases (83333 test cases)
Test #16:
score: 0
Accepted
time: 3ms
memory: 3500kb
input:
1 (()()((((())))(((((((())(()())())()(()((()(((()(()))))())((())((())((()))()())(()))()))((())()())))()())()(()((())(((()()(((())(((()))(((()())((()(((()())()())(()(()(())()()())())(((((((()((((()))()())())((((()(()())()())))((()((((()(((((()((((())()(()(()((((()()(((())())())))(())))))))))((((()(()...
output:
impossible
result:
ok 1 cases (1 test case)
Test #17:
score: 0
Accepted
time: 8ms
memory: 2516kb
input:
2 ())())()()(((()))()(((()())(())))))((()((()()()()()())(()((((()))()()((())()()((()))()())(())))(()(())(()()())(())))()())((((()()(()))((())()(())))))(((()(((((()(())()()((())))))(()(()())))))((())))))())())()()(()(()()))(((()))(()())))(())()))()())()()())()((()((()())())))())())((()((()())())(((()...
output:
())())()()(((()))()(((()())(())))))((()((()()()()()())(()((((()))()()((())()()((()))()())(())))(()(())(()()())(())))()())((((()()(()))((())()(())))))(((()(((((()(())()()((())))))(()(()())))))((())))))())())()()(()(()()))(((()))(()())))(())()))()())()()())()((()((()())())))())())((()((()())())(((()))...
result:
ok 2 cases (2 test cases)
Test #18:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
1 ()(()(()))()()()((()())(())())())()(())(()()(()))(())()()()((()(()(())(()()(()((((()()))))))())((()))))((())((((()))(((((()(()))(((())((()))()()((()(()((()((()()()))(())))(())())()()))))((((()(())))))((()(()((()()())())())(()())(()()))()((((()))())()(((()(())))()()((((()))))()))()()))))((())((()((...
output:
()(()(()))()()()((()())(())())())()(())(()()(()))(())()()()((()(()(())(()()(()((((()()))))))())((()))))((())((((()))(((((()(()))(((())((()))()()((()(()((()((()()()))(())))(())())()()))))((((()(())))))((()(()((()()())())())(()())(()()))()((((()))())()(((()(())))()()((((()))))()))()()))))((())((()(()(...
result:
ok 1 cases (1 test case)
Test #19:
score: 0
Accepted
time: 4ms
memory: 3528kb
input:
1 ()((()(((()))(())()())((()((()))((()()((()())(())())())(()()()()())(())(()((()(((())()((()((((((((())(()))))(((()()(()))(((()()())(()()(())))((((())()(()((()(())))()((())((((())())(()()()(()())((())(((()(((()))((()((()(()))))))())((())))((()))(((())))))))())(((((()(((())))(()())()()(())()(())(()()...
output:
()((()(((()))(())()())((()((()))((()()((()())(())())())(()()()()())(())(()((()(((())()((()((((((((())(()))))(((()()(()))(((()()())(()()(())))((((())()(()((()(())))()((())((((())())(()()()(()())((())(((()(((()))((()((()(()))))))())((())))((()))(((())))))))())(((((()(((())))(()())()()(())()(())(()())(...
result:
ok 1 cases (1 test case)
Test #20:
score: 0
Accepted
time: 8ms
memory: 3500kb
input:
1 )()((((())()))(())()))()(()))()())()(((()()(()(())))(()(((()))(((()()()))())))(())())()))(()((()))())()()()((((()))())))())((()())(()())))(((()(())()((()())(()((((())))(())))(()(())())(())(()()))(()((((()(())((())()()(((())()))(((()))(()(())(()()()()()()(())(((()()()(()(()(()))(()()))(((()((()()((...
output:
)()((((())()))(())()))()(()))()())()(((()()(()(())))(()(((()))(((()()()))())))(())())()))(()((()))())()()()((((()))())))())((()())(()())))(((()(())()((()())(()((((())))(())))(()(())())(())(()()))(()((((()(())((())()()(((())()))(((()))(()(())(()()()()()()(())(((()()()(()(()(()))(()()))(((()((()()(())...
result:
ok 1 cases (1 test case)
Test #21:
score: -100
Wrong Answer
time: 5ms
memory: 3480kb
input:
1 ())((()())()(((((()(((())()))((((()()))))))()())())(()())(())))())()((((()((()))))(()))))(((()(())((()()(()()(()))))()())))()))()(((())(()))))()()()(((((((())))(((()()))(())(()()))()))())))(((()((()())()()(((()()(((((((((())(()(())))(())()((()))))()((((())()(((()))))(()(())())(((()()(((((()(((()((...
output:
())((()())()(((((()(((())()))((((()()))))))()())())(()())(())))())()((((()((()))))(()))))(((()(())((()()(()()(()))))()())))()))()(((())(()))))()()()(((((((())))(((()()))(())(()()))()))())))(((()((()())()()(((()()(((((((((())(()(())))(())()((()))))()((((())()(((()))))(()(())())(((()()(((((()(((()(())...
result:
wrong answer the output is too long (test case 1)