QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678990 | #7683. Hard Brackets Problem | Displace_# | WA | 56ms | 3584kb | C++14 | 644b | 2024-10-26 16:36:29 | 2024-10-26 16:36:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+86;
int T;
string s;
int main()
{
cin>>T;
while(T--)
{
string as;
cin>>s;
int sm=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='(') sm++;
if(sm&&s[i]==')') sm--;
}
if(sm)
{
cout<<"impossible"<<endl;
continue;
}
int i=0,j=0;
while(i<s.size())
{
if(s[i]==')')
{
if(as[j]=='(') i++;
else as[++j]=s[i],i++;
}
else if(s[i]=='(')
{
if(s[i+1]=='(') as[++j]=s[i],i++;
else as[++j]=s[i],i+=2;
}
else i++;
}
for(int k=1;k<=j;k++) cout<<as[k];
cout<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
3 ((())) ( )))()
output:
((( impossible )))(
result:
ok 3 cases (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 56ms
memory: 3584kb
input:
100000 ())(()()() ()())())) )()()()() ())()(())( ((())())) )(())()))( )()))()))) )))))(((() ()))((()(( ()((()())) (()())()) ())(()))() (())(()))) ))))(()(() ()))(())(( ()((())()) ()))()))() ()((())()) ()()))((() ()))(())) (()(()))) ())((())) ())()((()) (()(()))) ()(((()()) ))))())))( ((((()()() (()(...
output:
impossible ((( )(((( impossible (((( impossible )(( impossible impossible ((((( (((( (((( (((( impossible impossible ((((( ((( ((((( impossible ((( (((( (((( impossible (((( impossible impossible impossible impossible impossible (((( impossible impossible impossible )))((( (((( (((( (((( impossible ...
result:
wrong answer the result string is incorrect (test case 2)