QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#733070 | #7683. Hard Brackets Problem | hoshinomiyako | WA | 0ms | 1580kb | C++14 | 1.1kb | 2024-11-10 17:03:39 | 2024-11-10 17:03:45 |
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;
nu=0;
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;
if(ll<0)a=0;
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
)))(
*/
/*
10
())(()()()
()())()))
)()()()()
())()(())(
((())()))
)(())()))(
)()))())))
)))))(((()
()))((()((
()((()()))
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1580kb
input:
3 ((())) ( )))()
output:
a(((b debug p=0 ll=2 a=3 b=3 impossible )))a(b debug p=3 ll=3 a=1 b=1
result:
wrong answer the answer string contains illegal characters (test case 1)