QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467077 | #7683. Hard Brackets Problem | adanmaip# | WA | 12ms | 1576kb | C++14 | 826b | 2024-07-08 13:39:40 | 2024-07-08 13:39:42 |
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;
int cntrgt=0;
for (int i=0; i<n; ++i){
if (a[i]=='('){
cntrgt=0;
++cntlft;
ans[ansi++]='(';
}
else if (a[i]==')'){
++cntrgt;
--cntlft;
ans[ansi++]=')';
}
}
if (cntlft>0) {
printf("impossible\n");
continue;
}
--ansi;
if (cntrgt>0) 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: 1536kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 1576kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
())(()()( ()())( )()()()( ())()(())( ((())( )(())()))( )()))( )))))(((( impossible ()((()( (()())( ())(()))( (())(( ))))(()(( ()))(())(( ()((())( ()))()))( ()((())( ()()))((( ()))(( (()(( ())((( ())()((( (()(( impossible ))))())))( impossible impossible impossible ())(()))( ))()(()(( (())()())( impo...
result:
wrong answer the result string is incorrect (test case 1)