QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733046 | #7683. Hard Brackets Problem | hoshinomiyako | WA | 12ms | 1608kb | C++14 | 985b | 2024-11-10 16:57:20 | 2024-11-10 16:57:20 |
Judging History
answer
#include <cstdio>
#include <cstring>
using namespace std;
char s[1000010];
int main()
{
int t=0,nu=0,l=0,p=0,ll=0,a=0,b=0;
scanf("%d",&t);
while(t--){
p=-1;
ll=-1;
scanf("%s",s);
l=strlen(s);
for(int i=0;i<l;++i){
if(s[i]=='('){
nu++;
ll=i;
if(i==0||s[i-1]==')')p=i;
}
else nu--;
if(nu<0)nu=0;
}
if(nu>0)printf("impossible\n");
else{
for(int i=0;i<p;++i)putchar(s[i]);
// putchar('a');
a=ll-p+1;
b=l-ll-1;
for(int i=0;i<a;++i)putchar('(');
// putchar('b');
if(b>a)for(int i=0;i<b;++i)putchar(')');
// printf("\ndebug p=%d ll=%d a=%d b=%d\n",p,ll,a,b);
putchar('\n');
}
}
return 0;
}
/*
4
((()))
(
)))()
((()))()
*/
/*
(((
impossible
)))(
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1608kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 12ms
memory: 1564kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ()())())) )()()()( impossible ((())())) impossible )()))()))) impossible impossible impossible impossible impossible (())(()))) impossible impossible impossible ()))()))( ()((())()) impossible ()))(())) (()(()))) ())((( impossible (()(()))) impossible impossible impossible impossible impo...
result:
wrong answer Jury has the answer but participant has not (test case 10)